title: Treating 7z files as .NET streams
body: <p>I would like to chain multiple stream operations (like downloading a file, uncompressing it on the fly, and processing the data without any temp files). The files are in 7z format. There is a LZMA SDK available, but forces me to create an outside output stream instead of being a stream itself - in other words the output stream will have to be fully written before I can work with it. SevenZipSharp also seems to be missing this functionality.</p>
  
  <p>Has anyone done something like that?</p>
  
  <pre><code>// 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
  }
  </code></pre>
  
  <p>Each file stream would behave like a read-once stream representing one file, and calling MoveNext() on the main compressed stream would automatically invalidate &amp; skip that file.</p>
  
  <p>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.</p>
  
  <p><strong>UPDATE 2012-01-06</strong></p>
  
  <p>#ziplib (SharpZipLib) already does exactly what I need for zip files with <code>ZipInputStream</code> class. Here is an example that yields all files as unseekable streams inside a given zip file. Still looking for 7z solution.</p>
  
  <pre><code>IEnumerable&lt;Stream&gt; UnZipStream(Stream stream)
  {
      using (var zipStream = new ZipInputStream(stream))
      {
          ZipEntry entry;
          while ((entry = zipStream.GetNextEntry()) != null)
              if (entry.IsFile)
                  yield return zipStream;
      }
  }
  </code></pre>