使用 Sharpcompress 创建 7zip 存档

发布于 2024-12-18 16:12:33 字数 600 浏览 2 评论 0原文

我需要使用 SharpCompress 将文件压缩为 7zip: http://sharpcompress.codeplex.com

我所做的如下:

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);
     }
 }

压缩过程已成功完成。但是,压缩文件无法使用 7z (http://www.7-zip.org/download.html) 或 winrar 解压。

不知道是否有人也遇到同样的问题并知道如何解决?

提前致谢。

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.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

带刺的爱情 2024-12-25 16:12:33

我是 SharpCompress 的作者(感谢您顺便尝试一下),并且不支持 7Zip 压缩: http://sharpcompress.codeplex.com/wikipage?title=Supported%20formats

您编写的是用于使用 LZMA 压缩创建标准 Zip 文件的代码。我的代码可能没有创建正确的 zip 文件,但也可能所有程序都无法读取创建的文件。 Zip 格式允许 LZMA 压缩,但并非所有程序都期望它。 PeaZip(基于 7Zip 存档器代码)确实使用 LZMA 提取 Zip,但 WinRAR 则不然。

如果您确实需要 7Zip 格式,我建议您使用其他格式。就我个人而言,我认为 7Zip 格式过于复杂,建议使用 Zip 或 Tar,然后选择您选择的压缩方式。

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.

阳光①夏 2024-12-25 16:12:33

SharpCompress 不支持 7zip 压缩。仅解压,参见:http://sharpcompress.codeplex.com/(支持的格式表)

即可使用7zip 的本机库进行压缩,或者使用它的开源包装器,例如: http://sevenzipsharp.codeplex.com/

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/

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文