.NET 3.5 中是否有内置的 zip 库?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/593026/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Is there a built-in zip library in .NET 3.5?
提问by Guy
Is there a built-in zip library in .NET 3.5?
.NET 3.5 中是否有内置的 zip 库?
If not, what are the popular open source .net zip libraries.
如果没有,什么是流行的开源 .net zip 库。
采纳答案by Cheeso
There is no built-in library. There are open-source options.
没有内置库。有开源选项。
DotNetZipis one. Simple, easy to use. It has good features: AES Encryption, regular encryption, streams, ZIP64, file comments, Unicode, progress events, more. And it's free and open source.
DotNetZip就是其中之一。简单,易于使用。它具有良好的功能:AES 加密、常规加密、流、ZIP64、文件注释、Unicode、进度事件等。而且它是免费和开源的。
Here's some sample code.
这是一些示例代码。
// extract all Photoshop files larger than 100mb
using (ZipFile zip1 = ZipFile.Read(ZipFileName))
{
var LargePhotoShopFiles = zip1.SelectEntries("name = *.psd and size > 100mb");
foreach (ZipEntry e in LargePhotoShopFiles)
{
if (e.UsesEncryption)
e.ExtractWithPassword("unpackDirectory", "VerySecret!");
else
e.Extract("unpackDirectory");
}
}
回答by Jon Skeet
EDIT: See note in comments - SharpZipLib is now unmaintained, and you probably want to avoid it.
编辑:请参阅注释中的注释 - SharpZipLib 现在未维护,您可能希望避免使用它。
Open source: #ZipLib
开源:#ZipLib
I believe that the classes in the System.IO.Compressionnamespace are fine for compressing/decompressing a single stream of data, but there's nothing built into the framework to cope with actual zip files.
我相信System.IO.Compression命名空间中的类适合压缩/解压缩单个数据流,但框架中没有内置任何内容来处理实际的 zip 文件。
EDIT: As noted in Ants' answer, there's System.IO.Packaging.ZipPackagebut it certainly lookslike that's really designed for use in WPF, and wouldn't be terribly convenient to use for general zip file handling. Worth looking into though. I wasn't aware of it before though... definitely worth investigating.
编辑:正如 Ants 的回答中所指出的,有System.IO.Packaging.ZipPackage但它看起来确实是为在 WPF 中使用而设计的,并且对于一般的 zip 文件处理来说并不是非常方便。不过值得研究。不过我之前不知道……绝对值得调查。
回答by Ants
Check out System.IO.Packaging.ZipPackage class.
查看 System.IO.Packaging.ZipPackage 类。
回答by Paul Rowland
回答by Inferis
Try System.IO.Compression.DeflateStream.
试试System.IO.Compression.DeflateStream。
回答by Mash
I will be second to recommend http://www.7-zip.org/sdk.htmlLZMA SDK, but it's not ZIP.
我将第二个推荐http://www.7-zip.org/sdk.htmlLZMA SDK,但它不是 ZIP。
- It's in public domain
- It's FAST on decompression
- It has fully managed implementation
- It's much better compressing than ZIP/RAR
- It has very small footprint
- It can work as a stream
- 它在公共领域
- 解压速度很快
- 它具有完全托管的实施
- 它比 ZIP/RAR 压缩得更好
- 它的占地面积非常小
- 它可以作为流工作
回答by Arthur Stankevich
System.IO.Compression has ZipArchiveclass as of .Net 4.5.
从 .Net 4.5 开始,System.IO.Compression 具有ZipArchive类。

