Skip to content

Utility.Skip uses seek - #336

Merged
adamhathcock merged 1 commit into
adamhathcock:masterfrom
diontools:ImproveStreamSkipping
Jan 10, 2018
Merged

adamhathcock merged 1 commit into
adamhathcock:masterfrom
diontools:ImproveStreamSkipping

Conversation

@diontools

Copy link
Copy Markdown

Hello.
I have a large zip file.(~100GB 871kEntries)
I tried below code.

var sw = Stopwatch.StartNew();
using (var stream = new FileStream(@"large.zip", FileMode.Open, FileAccess.Read, FileShare.Read))
using (var reader = ZipReader.Open(stream, new SharpCompress.Readers.ReaderOptions { LeaveStreamOpen = true }))
{
    while (reader.MoveToNextEntry())
    {
        //Console.WriteLine(reader.Entry.Key);
    }
}
Console.WriteLine(sw.Elapsed);

It took about 13 minutes in my machine.
However, when this PR is applied, it was shortened to 10 seconds.
Does this cause problems?

I'm sorry for my poor English.
Thank you for reading.

@adamhathcock

Copy link
Copy Markdown
Owner

Use the Archive API for random access. The Reader API intentionally doesn’t use Seek

@simmotech

Copy link
Copy Markdown

The change conditionally uses CanSeek to perform a Skip much quicker where possible - why is this considered wrong?

@diontools

Copy link
Copy Markdown
Author

Thank you for reply.
I understood Reader spec.

Archive API is very useful, but since Entry is cached, memory space is needed.
In my file it will be about 400 MB.
I'd like to reduce a little more.

I'm trying to extract some files from Zip.
I hope a way to filter Entry.
For example, it is like this.

using (var zip = ZipArchive.Open(stream, ...))
{
    foreach (var entry in zip.LoadEntries())
    {
        if (IsTargetFile(entry.Key))
        {
            entry.WriteToDirectory(...);
        }
    }
}

Current ZipArchive.LoadEntries is protected, but I think that it would be nice if there was an API similar to this.
Thank you for reading.

@adamhathcock

Copy link
Copy Markdown
Owner

Fair enough. I shouldn’t be so rigid. Hopefully no streams throw when accessing CanSeek

@diontools

Copy link
Copy Markdown
Author

Thank you so much. PR closing.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants