.Net中的7Zip——Sharpcompress

虽然微软在.net 4.5中集成了对zip的解压支持,但还是比较弱。如果我们想让程序像7zip那样支持万能解压,Sharpcompress可以帮你实现这个目标,它是一个C#写的压缩/解压工具,虽然还没能做得像7Zip那么NB,当支持的格式也是相当多的,如下就是目前的支持情况:

Archive Format

Compression Format(s)

Compress/Decompress

Archive API

Reader API

Writer API

Rar

Rar

Decompress(1)

RarArchive

RarReader

N/A

Zip(2)

None, DEFLATE, BZip2, LZMA/LZMA2, PPMd

Both

ZipArchive

ZipReader

ZipWriter

Tar

None, BZip2, GZip

Both

TarArchive

TarReader

TarWriter(3)

GZip (single file)

GZip

Both

GZipArchive

GZipReader

GZipWriter

7Zip(4)

LZMA, LZMA2, BZip2, PPMd, BCJ, BCJ2

Decompress

SevenZipArchive

N/A

N/A

(1) SOLID Rars are only supported in the RarReader API.
(2) Zip format supports pkware and WinzipAES encryption. However, encrypted LZMA is not supported.
(3) The Tar format requires a file size in the header. If no size is specified to the TarWriter and the stream is not seekable, then an exception will be thrown.
(4) The 7Zip format doesn‘t allow for reading as a forward-only stream so 7Zip is only supported through the Archive API

并且这个库是一个portable的,.NET/Mono/Silverlight/WP7等框架都可以用,还等什么,赶紧安装吧:

    PM> Install-Package sharpcompress

并且它也在NUGET上提供了一些范例:

    PM> Install-Package p3-sharpcompress

如果要更详细的了解它,可以参看它的项目主页:

郑重声明:本站内容如果来自互联网及其他传播媒体,其版权均属原媒体及文章作者所有。转载目的在于传递更多信息及用于网络分享,并不代表本站赞同其观点和对其真实性负责,也不构成任何其他建议。