deflate compression without archive container

May 13, 2009 at 3:08 PM


  Firstly, thanks very much for your library.  It's wonderful to have the .7z and other archives support available for my C# project.  I am currently working with an emulated music format that stores data in a zlib deflated chunk within the file.  I wanted to experiment with the 7zip deflate algorithm to achieve better compression than the original zlib deflate.  The only problem is that using "SevenZipCompressor" object requires the "ArchiveFormat" member be populated (since it is non-nullable).  For my uses, I simply need the deflated stream without the archive container. 

May I request that an option, "OutArchiveFormat.None" be added so code similar to the following could output a zlib deflated stream without a 7z/Zip/etc... container?  You may have a better idea on implementation, but it would be nice to have access to the deflated stream without a container.

SevenZipCompressor compressor = new SevenZipCompressor();
compressor.CompressionMethod = CompressionMethod.Deflate;         
compressor.ArchiveFormat = OutArchiveFormat.None;

compressor.CompressStream(pInStream, pOutStream);


Thanks again for the library!


May 16, 2009 at 8:19 AM
Edited May 19, 2009 at 12:38 PM


I am sorry to disappoint you but due to the fixed feature set of the native 7z.dll library, it is impossible to implement the feature you ask.

But, if you want just a compressed stream without a container, why not use LZMA compressed stream. Apart from the compression method (LZMA instead of DEFLATE), it fits your demands. LZMA compression implemented is fully managed (no calls to 7z.dll, the algorithm is written in C#), it compresses much better than DEFLATE. One may experience a slight decrease in speed - the only drawback.

To compress a stream with LZMA, use the following code:


SevenZipCompressor.CompressStream(pInStream, pOutStream, null,

//The code below is not necessary, it shows the compression progress. For no progress output, just write "null" here

(o, e) =>
                if (e.PercentDelta > 0)
                    Console.WriteLine(e.PercentDone.ToString() + "%");

Greetings, Vadim.

May 18, 2009 at 6:27 PM

Thanks for looking into this, I appreciate all the great work.  I'll give your suggestion a shot.

May 21, 2009 at 7:42 PM

Lots of file type internally use DFALATE chunks internally to store data in compressed form. Certainly PNG and MNG files use it. If we had the feature asked by snakemeat, certainly it would have helped to achieve better compression in those type of files with SevenZipSharp. But, we may have to ask Igor to implement the feature in 7z.dll.