1

I need to compress a file as 7zip using SharpCompress: http://sharpcompress.codeplex.com

what I have done as follows:

using (var archive = ZipArchive.Create())
{
     archive.AddEntry("CompressionTest.pdb", new FileInfo("CompressionTest.pdb"));

     using (Stream newStream = File.Create("CompressionTest212.7z"))
     {
         archive.SaveTo(newStream, SharpCompress.Common.CompressionType.LZMA);
     }
 }

The compression process is done successfully. However, the compressed file can not be extracted either using 7z (http://www.7-zip.org/download.html) or winrar.

I dont know if somebody also got the same problem and had an idea how to solve it?

Thanks in advance.

Adriano Repetti
  • 65,416
  • 20
  • 137
  • 208
olidev
  • 20,058
  • 51
  • 133
  • 197

2 Answers2

8

I'm the author of SharpCompress (thanks for trying it out by the way) and 7Zip compression isn't supported: http://sharpcompress.codeplex.com/wikipage?title=Supported%20formats

What you wrote is code for creating a standard Zip file with LZMA compression. It's possible my code does not create a proper zip file but it's also possible that the created file can't be read by all programs. The Zip format allows for LZMA compression but not all programs may expect it. PeaZip (based on the 7Zip archiver code) does extract a Zip with LZMA, but WinRAR does not.

If you really need the 7Zip format, I do suggest using something else. Personally, I think the 7Zip format is overly complex and recommend Zip or Tar then just pick your compression of choice.

adamhathcock
  • 313
  • 1
  • 7
2

SharpCompress doesn't support 7zip compression. Only decompression, see: http://sharpcompress.codeplex.com/ ( Supported Format Table )

You can use the native library of 7zip for compression, or use an opensource wrapper around it like: http://sevenzipsharp.codeplex.com/

Polity
  • 14,734
  • 2
  • 40
  • 40
  • thanks. however, the compression seems working but it is slightly diffrent with using 7z from 7-zip.org – olidev Dec 01 '11 at 09:04
  • Well, better ask the author, yet i quess if this feauture was supported, he would definatly promote it. Could it be still under development? – Polity Dec 01 '11 at 09:53