This project is read-only.

Streaming individual files inside the 7z files

Sep 14, 2010 at 5:01 PM
Edited Sep 14, 2010 at 5:01 PM
I might be wrong, but I saw this brought up a few times in this forum, and looked through the code, but still there seems to be one critical part not fully implemented - an ability for a 7z file to be treated as a one way (either readonly or writeonly) stream. It would allow us to perform filter-like chaining of multiple operations:
// in pseudo-code - CompressedFileStream derives from Stream
foreach (CompressedFileStream f in SevenZip.UncompressFiles(Web.GetStreamFromWeb(url))
    Console.WriteLine("Processing file {0}", f.Name);
    ProcessStream( f ); // further streaming, like decoding, processing, etc

Each file stream would behave like a read-once stream representing one file, and calling MoveNext() on the main compressed stream would automatically invalidate & skip that file.

Similar constructs can be done for compression. Example usage - do some aggregation on a very large quantity of data - for each 7z file in a dir, for each file inside, for each data line in each file, sum up some value.

Jan 6, 2012 at 5:47 PM
Edited Jan 6, 2012 at 6:09 PM

I noticed that #ziplib (SharpZipLib) already implements this feature. Are there any discussion of implementing it here as well? Example:

IEnumerable<Stream> UnZipStream(Stream stream)
    using (var zipStream = new ZipInputStream(stream))
        ZipEntry entry;
        while ((entry = zipStream.GetNextEntry()) != null)
            if (entry.IsFile)
                yield return zipStream;