create an 7zip archive with sharpcompress
Asked Answered
M

2

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.

Mesencephalon answered 1/12, 2011 at 1:55 Comment(0)
K
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/

Knickerbocker answered 1/12, 2011 at 2:5 Comment(2)
thanks. however, the compression seems working but it is slightly diffrent with using 7z from 7-zip.orgMesencephalon
Well, better ask the author, yet i quess if this feauture was supported, he would definatly promote it. Could it be still under development?Knickerbocker
F
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.

Fusible answered 25/1, 2012 at 8:52 Comment(1)
Hi @adamhathcock, is that still the same state for SharpCompress library, not having support for creating/writing 7z archives? I am exploring libraries for creating 7z format archives via dotnet.Sexagesimal
K
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/

Knickerbocker answered 1/12, 2011 at 2:5 Comment(2)
thanks. however, the compression seems working but it is slightly diffrent with using 7z from 7-zip.orgMesencephalon
Well, better ask the author, yet i quess if this feauture was supported, he would definatly promote it. Could it be still under development?Knickerbocker

© 2022 - 2024 — McMap. All rights reserved.