雖然微軟在.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
如果要更詳細的了解它,可以參看它的項目主頁1:
-
CodePlex:https://sharpcompress.codeplex.com/