Quantcast
Channel: sharpcompress Discussions Rss Feed
Viewing all 239 articles
Browse latest View live

New Post: Attempting to access last modified time I get NotImplementedException

$
0
0
Same accessing an entry comment - ZipWritableArchiveEntry.cs explicitly replaces the ZipEntry.cs definition of Parts with the exception...
WIP I'd guess.

New Post: Writing files to a Zip using AddEntry/SaveTo: Streams are closed late.

$
0
0
Mounting the horse from the rear: I built a fork of 10.1.3 with a ZipArchive.cs SaveTo reading as follows:
    protected override void SaveTo(Stream stream, CompressionInfo compressionInfo,
                                   IEnumerable<ZipArchiveEntry> oldEntries,
                                   IEnumerable<ZipArchiveEntry> newEntries)
    {
        using (var writer = new ZipWriter(stream, compressionInfo, string.Empty))
        {
            foreach (var entry in oldEntries.Concat(newEntries)
                                            .Where(x => !x.IsDirectory))
            {
                using (var entryStream = entry.OpenEntryStream())
                {
                    writer.Write(entry.FilePath, entryStream, entry.LastModifiedTime, string.Empty);
                }
                entry.Close();
            }
        }
    }
Only change is the entry.Close() call.

Use case: Move images to a cbz (http://en.wikipedia.org/wiki/Comic_Book_Archive_file). With your build, one must call GC.Collect() after saving the archive but before recycling the freshly archived originals, my fork doesn't need it.

Personally, I don't like the notion at all that some code allocates a resource and does not also implement a predictable path to the release of said resource. AbstractWritableArchive.cs line 106 has such an fileInfo.OpenRead() where no corresponding closure is to be seen in the vicinity... Though I couldn't really suggest something constructive.

This architecture also means all entry source streams are opened and held at the same time, requiring more resources than strictly necessary (see also http://blogs.technet.com/b/markrussinovich/archive/2009/09/29/3283844.aspx), and possibly limiting the number of files that can be added to an archive prematurely (think old C CRT: 2048 maximum).

(Yes, I know the Writer API probably will not suffer from these effects)

New Post: Multi-file Archive support

$
0
0
If you do RarArchive.Open(string) with a file path for the first rar archive. It should work. Zip multi-file archives aren't currently supported.

New Post: Writing files to a Zip using AddEntry/SaveTo: Streams are closed late.

$
0
0
Are you basically stating that the EntryStream doesn't dispose properly? What does your entry.Close method do?

I agree that the resources should be released predictably. I thought the entry classes were lightweight enough to not need an explicit Dispose or Close. I guess it's my mistake as I believe I do open FileStreams even though I'm not using them.

This is a valid concern and one I will attempt to fix in the future. However, I am very time limited and don't often get time to do big features/fixes.

New Post: aync decompression

$
0
0
Hi!

I have many textfiles in a WinRar file, and I want to parse them on the fly, while I am doing the decompression. I did see that the decompression uses lots of CPU on one of the cores, so I want to do the parsing (which also uses lots of cpu) on another thread. Is this possible? Are there samples?

Thanks Walter.

New Post: Invalid Rar Header: 174

$
0
0
I sometimes do get " Invalid Rar Header: 174" exceptions, when I do process RAR files.
The rar files are ok. I basically scan for interesting data in the binary streams of
all files in a rar file.

fileStreamIn = new FileStream(fileName, FileMode.Open, FileAccess.Read,FileShare.ReadWrite,1024222222,FileOptions.SequentialScan );
reader=SharpCompress.Reader.ReaderFactory.Open(fileStreamIn,SharpCompress.Common.Options.LookForHeader);

while ( reader.MoveToNextEntry())
{
if (!reader.Entry.IsDirectory)
{
entryStream = reader.OpenEntryStream ();
if (entryStream.CanRead)
{
logfileParser.ProcessStream(entryStream);
 } 
}
}

This is the exception:
: Invalid Rar Header: 174
Source: SharpCompress
Data: System.Collections.ListDictionaryInternal
HelpLink
TargetSite bei SharpCompress.Common.Rar.Headers.RarHeaderFactory.ReadNextHeader(Stream stream)
bei SharpCompress.Common.Rar.Headers.RarHeaderFactory.<ReadHeaders>d__0.MoveNext()
bei SharpCompress.Common.Rar.RarVolume.<GetVolumeFileParts>d__0.MoveNext()
bei SharpCompress.Reader.Rar.RarReader.<GetEntries>d__0.MoveNext()
bei SharpCompress.Reader.AbstractReader2.NextEntryForCurrentStream()
bei SharpCompress.Reader.AbstractReader
2.MoveToNextEntry()


Any ideas??
Regards
Walter

New Post: NotImplementedException throwed when read a stream

$
0
0
Hi,

I want to read a compressed stream using SharpCompress to decompress the stream but a NotImplementedException is throwed when I tried to do it. Here is the code:
Stream stream = await GetStreamAsync(uri);

                if (stream == null)
                {
                    return null;
                }

                stream = new GZipStream(stream, CompressionMode.Decompress);
String textResult;
                using (var streamReader = new StreamReader(stream))
                {
                    textResult = await streamReader.ReadToEndAsync(); // Throws the exception
                }
Here is the stacktrace:
   at SharpCompress.Compressor.Deflate.GZipStream.get_Length()
   at System.IO.StreamReader.ReadToEnd()
   at AsyncExtensions.<>c__DisplayClass12.<ReadToEndAsync>b__11()
   at System.Threading.Tasks.Task`1.InvokeFuture(Object futureAsObj)
   at System.Threading.Tasks.Task.InnerInvoke()
   at System.Threading.Tasks.Task.Execute()
   at System.Threading.Tasks.Task.ExecuteWithThreadLocal()
   at System.Threading.Tasks.Task.ExecuteEntry(Boolean bPreventDoubleExecution)
   at System.Threading.Tasks.TaskScheduler.TryExecuteTask(Task task)
   at System.Threading.Tasks.ThreadPoolTaskScheduler.<.ctor>b__0(Object state)
   at System.Threading.ThreadPool.WorkItem.WaitCallback_Context(Object state)
   at System.Threading.ExecutionContext.Run(ExecutionContext executionContext, ContextCallback callback, Object state)
   at System.Threading.ThreadPool.WorkItem.doWork(Object o)
   at System.Threading.Timer.ring()
Best

New Post: aync decompression

$
0
0
With RAR files, you could access the files via the Archive interface and decompress each entry on different threads. As long as they're not SOLID RARs then they can be decompressed in different threads.

Sorry, I don't have any samples for this though.

New Post: NotImplementedException throwed when read a stream

$
0
0
I guess ReadToEnd requires length to properly function. GZipStream is a forward-only stream implementation so length won't necessarily be known (like if you're using a NetworkStream).

Can you do without ReadToEnd?

New Post: Invalid Rar Header: 174

$
0
0
Either they're RAR5 format or...well...I dunno :)

I'd need a sample file to see what the potential issue is when reading the format.

New Post: VB Non-responsive app when loading

$
0
0
Ok so, I dont know if this is the right area first of all... But ill give it a shot.

Pretty much, as VB does, when a thread/function is in the process of being operated, the program becomes unresponsive (you cant do anything till that function is done executing)

This is a problem for me...

What I am trying to do is: When the form loads, it will launch a timer, on the timers event, what it should be doing is, displaying in a label what item it is currently in the process of unzipping, then after it is done, check that item off in the checkedlistbox below.

What is happening is: When the form loads, it ill launch the timer, and on the timers event, it will display the current item being unzipped, and when that item is done, check it off on the checklistbox below, however you CANNOT see any of this happen, until it is done executing the code, it is only done executing the code once the last item is finished unzipping, then you will instantly see all the items go from unchecked to checked, and it say "Finished extracting"... Which defeats the entire purpose.

So, what I want to know is: How do I make it so that you can actually SEE whats going on as it is happening, and the user can still interact (scroll down the list of items) with the program, while it is unzipping, and the user can actually see what item its currently on, and what items are done (indicated by it being checked or not)?

I have all this code on a timer right now(with a 1 interval (1 millisecond)):

[code]
    For Each file In archive.Entries
        label1.Text = "Currently Unzipping: " & file.FilePath & "..."
        If file.IsComplete = True Then
            'Check off each item once it is actually finished extracting to its destination...
            CheckedListBox.SetItemChecked(CheckedListBox.Items.IndexOf(file.FilePath), True)
        End If
    Next
[/code]

New Post: 'System.ArgumentOutOfRangeException' occurred in mscorlib.dll

$
0
0
An unhandled exception of type 'System.ArgumentOutOfRangeException' occurred in mscorlib.dll

I'm using VB.

Anyone else running into this?
I'm trying to write a utility to batch extract many .rar files at once. I want to be able to use a Listbox or Checkbox to select what .rar's I want to extract.

The only way I seem to be able to get anything to work is by passing the source file as a string variable from an openFileDialogue box. I have even tried to specify the source path as a string with no success. You can see the other methods I've tried with no success. Code snippet below:
Public diagPath As String

    Public Sub ButtonTest_Click(sender As Object, e As EventArgs) Handles ButtonTest.Click
        
        'OpenFileDialog1.ShowDialog()
        'Dim diagPath As String = OpenFileDialog1.FileName.ToString
       
        'Dim diagPath As String = ListBox1.SelectedItem.ToString
        'Dim diagPath As String = TextBoxFilesPath.Text.ToString
        'Dim diagPath As String = CheckedListBox1.CheckedItems.ToString
        

For Each diagPath2 In CheckedListBox1.CheckedItems
            diagPath = diagPath2.ToString
            ArchiveFactory.WriteToDirectory(diagPath, "C:\WiiShare\Uncomp", ExtractOptions.ExtractFullPath)
            MsgBox("done")
            
Next

    End Sub
To reiterate, if I call the OpenFileDialogue and use the filename as the ArchiveFactory.writetodirectory source path, it works. If I use any other method to define the source path, I get the ArgumentOutOfRangeException error.

Would someone mind offering some advice?

New Post: VB Non-responsive app when loading

$
0
0
Your basic problem is that you need to not do a lot of work on the UI thread. You need to look at using something like BackgroundWorker to do work on a different thread.

New Post: 'System.ArgumentOutOfRangeException' occurred in mscorlib.dll

$
0
0
I'm slightly confused on what you're doing to get the out of range exception. I'd like to see a non-working sample and a call stack when the exception is hit.

New Post: 'System.ArgumentOutOfRangeException' occurred in mscorlib.dll

$
0
0
Admittedly, I've never provided that before so please let me know if there's anything thing else I can provide. And thank you for looking into this for me.

here is a copy/paste of what appears in the Call Stack window:
    mscorlib.dll!System.ThrowHelper.ThrowArgumentOutOfRangeException(System.ExceptionArgument argument, System.ExceptionResource resource)  Unknown
    mscorlib.dll!System.BitConverter.ToInt16(byte[] value, int startIndex)  Unknown
    SharpCompress.dll!SharpCompress.IO.MarkingBinaryReader.ReadInt16()  Unknown
    SharpCompress.dll!SharpCompress.Common.Rar.Headers.RarHeader.ReadFromReader(SharpCompress.IO.MarkingBinaryReader reader)    Unknown
    SharpCompress.dll!SharpCompress.Common.Rar.Headers.RarHeader.Create(SharpCompress.IO.MarkingBinaryReader reader)    Unknown
    SharpCompress.dll!SharpCompress.Common.Rar.Headers.RarHeaderFactory.ReadNextHeader(System.IO.Stream stream) Unknown
    SharpCompress.dll!SharpCompress.Common.Rar.Headers.RarHeaderFactory.ReadHeaders()   Unknown
    SharpCompress.dll!SharpCompress.Common.Rar.RarVolume.GetVolumeFileParts()   Unknown
    mscorlib.dll!System.Collections.Generic.List<SharpCompress.Common.Rar.RarFilePart>.List(System.Collections.Generic.IEnumerable<SharpCompress.Common.Rar.RarFilePart> collection)    Unknown
    System.Core.dll!System.Linq.Enumerable.ToList<SharpCompress.Common.Rar.RarFilePart>(System.Collections.Generic.IEnumerable<SharpCompress.Common.Rar.RarFilePart> source)    Unknown
    SharpCompress.dll!SharpCompress.Utility.ToReadOnly<SharpCompress.Common.Rar.RarFilePart>(System.Collections.Generic.IEnumerable<SharpCompress.Common.Rar.RarFilePart> items)    Unknown
    SharpCompress.dll!SharpCompress.Archive.Rar.FileInfoRarArchiveVolume.FileInfoRarArchiveVolume(System.IO.FileInfo fileInfo, SharpCompress.Common.Options options)    Unknown
    SharpCompress.dll!SharpCompress.Archive.Rar.RarArchiveVolumeFactory.GetParts()  Unknown
    SharpCompress.dll!SharpCompress.LazyReadOnlyCollection<SharpCompress.Common.Rar.RarVolume>.LazyLoader.MoveNext()    Unknown
    SharpCompress.dll!SharpCompress.Archive.Rar.RarArchiveEntryFactory.GetFileParts()   Unknown
    SharpCompress.dll!SharpCompress.Archive.Rar.RarArchiveEntryFactory.GetMatchedFileParts()    Unknown
    SharpCompress.dll!SharpCompress.Archive.Rar.RarArchiveEntryFactory.GetEntries() Unknown
    SharpCompress.dll!SharpCompress.LazyReadOnlyCollection<SharpCompress.Archive.Rar.RarArchiveEntry>.LazyLoader.MoveNext() Unknown
    SharpCompress.dll!SharpCompress.Archive.ArchiveFactory.WriteToDirectory(string sourceArchive, string destinationDirectory, SharpCompress.Common.ExtractOptions options) Unknown
>   defraggg.exe!defraggg.Form1.ButtonTest_Click(Object sender, System.EventArgs e) Line 96 Basic
    System.Windows.Forms.dll!System.Windows.Forms.Control.OnClick(System.EventArgs e)   Unknown
    System.Windows.Forms.dll!System.Windows.Forms.Button.OnClick(System.EventArgs e)    Unknown
    System.Windows.Forms.dll!System.Windows.Forms.Button.OnMouseUp(System.Windows.Forms.MouseEventArgs mevent)  Unknown
    System.Windows.Forms.dll!System.Windows.Forms.Control.WmMouseUp(ref System.Windows.Forms.Message m, System.Windows.Forms.MouseButtons button, int clicks)   Unknown
    System.Windows.Forms.dll!System.Windows.Forms.Control.WndProc(ref System.Windows.Forms.Message m)   Unknown
    System.Windows.Forms.dll!System.Windows.Forms.ButtonBase.WndProc(ref System.Windows.Forms.Message m)    Unknown
    System.Windows.Forms.dll!System.Windows.Forms.Button.WndProc(ref System.Windows.Forms.Message m)    Unknown
    System.Windows.Forms.dll!System.Windows.Forms.Control.ControlNativeWindow.OnMessage(ref System.Windows.Forms.Message m) Unknown
    System.Windows.Forms.dll!System.Windows.Forms.Control.ControlNativeWindow.WndProc(ref System.Windows.Forms.Message m)   Unknown
    System.Windows.Forms.dll!System.Windows.Forms.NativeWindow.DebuggableCallback(System.IntPtr hWnd, int msg, System.IntPtr wparam, System.IntPtr lparam)  Unknown
    [Native to Managed Transition]  
    [Managed to Native Transition]  
    System.Windows.Forms.dll!System.Windows.Forms.Application.ComponentManager.System.Windows.Forms.UnsafeNativeMethods.IMsoComponentManager.FPushMessageLoop(System.IntPtr dwComponentID, int reason, int pvLoopData)  Unknown
    System.Windows.Forms.dll!System.Windows.Forms.Application.ThreadContext.RunMessageLoopInner(int reason, System.Windows.Forms.ApplicationContext context)    Unknown
    System.Windows.Forms.dll!System.Windows.Forms.Application.ThreadContext.RunMessageLoop(int reason, System.Windows.Forms.ApplicationContext context) Unknown
    System.Windows.Forms.dll!System.Windows.Forms.Application.Run(System.Windows.Forms.ApplicationContext context)  Unknown
    Microsoft.VisualBasic.dll!Microsoft.VisualBasic.ApplicationServices.WindowsFormsApplicationBase.OnRun() Unknown
    Microsoft.VisualBasic.dll!Microsoft.VisualBasic.ApplicationServices.WindowsFormsApplicationBase.DoApplicationModel()    Unknown
    Microsoft.VisualBasic.dll!Microsoft.VisualBasic.ApplicationServices.WindowsFormsApplicationBase.Run(string[] commandLine)   Unknown
    [Native to Managed Transition]  
    mscorlib.dll!System.AppDomain.ExecuteAssembly(string assemblyFile, System.Security.Policy.Evidence assemblySecurity, string[] args) Unknown
    Microsoft.VisualStudio.HostingProcess.Utilities.dll!Microsoft.VisualStudio.HostingProcess.HostProc.RunUsersAssembly()   Unknown
    mscorlib.dll!System.Threading.ThreadHelper.ThreadStart_Context(object state)    Unknown
    mscorlib.dll!System.Threading.ExecutionContext.RunInternal(System.Threading.ExecutionContext executionContext, System.Threading.ContextCallback callback, object state, bool preserveSyncCtx)   Unknown
    mscorlib.dll!System.Threading.ExecutionContext.Run(System.Threading.ExecutionContext executionContext, System.Threading.ContextCallback callback, object state, bool preserveSyncCtx)   Unknown
    mscorlib.dll!System.Threading.ExecutionContext.Run(System.Threading.ExecutionContext executionContext, System.Threading.ContextCallback callback, object state) Unknown
    mscorlib.dll!System.Threading.ThreadHelper.ThreadStart()    Unknown
to clarify a little more. This works fine:
OpenFileDialog1.ShowDialog()
Dim diagPath As String = OpenFileDialog1.FileName.ToString
ArchiveFactory.WriteToDirectory(diagPath, "C:\WiiShare\Uncomp", ExtractOptions.ExtractFullPath)
I can open an OpenFileDialog box and pass the file path, as a string (diagPath), to ArchiveFactory.WriteToDirectory. No problems. All I have to do is pick the .rar file and it picks up the whole collection.

However, if I try to pick the file path from an item in a ListBox, like this:
Dim diagPath As String = ListBox1.SelectedItem.ToString
ArchiveFactory.WriteToDirectory(diagPath, "C:\WiiShare\Uncomp", ExtractOptions.ExtractFullPath)
It won't. When I pause to debug, the file path is a string, for sure. I have the listbox set to make single selections only. I have even tried to pass the filepath to a textbox, then to a string variable, and then into ArchiveFactory.

The last thing I want to look at is mscorlib.dll. Have you ever run into problems with this file before? I'm thinking I might try to run this project on another computer this week to see if it makes a difference.

Thanks again for any help/advice you can offer.

New Post: 'System.ArgumentOutOfRangeException' occurred in mscorlib.dll

$
0
0
Update... I suspected mscorlib.dll might have been the culprit so I tried this project on a newer system. No luck. Next I will try the code in an earlier version of vb. I'm currently using visual studio 2013 express for desktop.

I really can't see any reason why my code won't work. It's not like it's complicated.

New Post: 'System.ArgumentOutOfRangeException' occurred in mscorlib.dll

$
0
0
The only way you can get an error is like is if the file you're giving SharpCompress is a bad or invalid archive.

Since you're saying that you can hardcore the path and make it work, I can only assume there's not anything wrong with SharpCompress.

The path in your second case has to be wrong. I can't help anything beyond that.

New Post: Going into subdirectories when extracting?

$
0
0
I can't find a way to go into subdirectories while extracting an archive.

An archive entry has an IsDirectory flag, but there doesn't seem to be anything to do with a directory entry. I would expect it to have a collection of entries to iterate.

All of the examples and the test cases just skip directories.

Am I missing something obvious, or is there no support for nested directories?

Thanks!

New Post: Going into subdirectories when extracting?

New Post: Going into subdirectories when extracting?

$
0
0
Thanks for getting back to me, Adam.

I'm talking about an archive that looks like this:
  • file1
  • file2
  • directory1
    • file3
    • file4
When I enumerate the archives, I can extract "file1" and "file2" just fine. When I get to "directory1", it has the IsDirectory flag set (as it should), but I don't see any way to get to file "file3" and "file4".

Thanks for your help!
Viewing all 239 articles
Browse latest View live


<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>