DotNetZip 1.3 Release (2008/2/5)

摘要:DotNetZip 1.3 Release (2008/2/5)

DotNet Zip Library 是我覺得 SharpZip 之外另一個比較好用的壓縮與解壓縮的類別庫。

Project Description
The Microsoft .NET Framework {v2.0 v3.0 v3.5} includes base class libraries supporting compression within streams - both the Deflate and Gzip formats are supported. But the System.IO.Compression namespace provides streaming compression only - useful for communicating between cooperating parties but not directly useful for creating compressed archives, like .zip files. The built-in compression library does not know how to format zip archive headers and so on.

To address this, this simple class library augments the System.IO.Compression.DeflateStream class, to provide handling for Zip files. Using this library, you can write .NET applications that read and write zip-format files.

Frequently Asked Questions


How does this Zip Library work?
There's a single DLL, a single assembly, fully managed code, written in C#, that provides support for reading and writing Zip archive files.

What do I need to "do" zip files from within my application?
To use the zip capability in your applications, you need to be using the .NET Framework 2.0 or later. You can use the Zip library from any application, whether a console application, a Windows-Forms application, a server-based application, or something else.

How big is the library?
The zip DLL is about 36k in size. There is no other pre-requisite.

Limitations
---------------------------------

There are numerous limitations to this library:

it does NOT support encryption, file comments, or double-byte chars in filenames.

it does NOT support file lengths greater than 0xffffffff.

it does NOT support "multi-disk archives."

it does NOT do varying compression levels.

it can actually expand the size of previously compressed data, such as JPG files.

there is no GUI tool

簡單範例:

   1:  /* 將 C:\TMP\TMP2\01.jpg 檔案壓縮至 test01.zip 檔案中的 TMP\TMP2\01.jpg  
   2:   * 將 D:\02.jpg 檔案壓縮至 test01.zip 檔案中的 02.jpg  
   3:   * 將 C:\TMP\03.jpg 檔案壓縮至 test01.zip 檔案中的 TMP\03.jpg
   4:   */
   5:  using (ZipFile zip = new ZipFile(@"C:\test01.zip"))
   6:  {
   7:      zip.AddFile(@"C:\TMP\TMP2\01.jpg");
   8:      zip.AddFile(@"D:\02.jpg");
   9:      zip.AddFile(@"C:\TMP\03.jpg");
  10:      zip.Save();
  11:  }
  12:   
  13:  // 將 TMP2 目錄壓縮至 test02.zip 檔案中的 TMP\TMP2 目錄
  14:  using (ZipFile zip = new ZipFile(@"C:\test02.zip"))
  15:  {
  16:      zip.AddDirectory(@"C:\TMP\TMP2");
  17:      zip.Save();
  18:  }
  19:   
  20:  /* 將 TMP2 目錄壓縮至 test03.zip 檔案中的 TTT 目錄 
  21:   * 將 C:\TMP\03.jpg 檔案壓縮至 test03.zip 檔案中的 TTT\03.jpg 
  22:   */
  23:  using (ZipFile zip = new ZipFile(@"C:\test03.zip"))
  24:  {
  25:      zip.AddFile(@"C:\TMP\03.jpg", "TTT");
  26:      zip.AddItem(@"C:\TMP\TMP2", "TTT");
  27:      zip.Save();
  28:  }
  29:   
  30:  // 將 C:\test03.zip 檔案解壓縮至 C:\
  31:  using (ZipFile zip = new ZipFile(@"C:\test03.zip"))
  32:  {
  33:      zip.ExtractAll(@"C:\");
  34:  }