DotNetZip 1.7 Release (2009/2/10)

DotNetZip 1.7 Release (2009/2/10)

感謝 DotNetZip 作者 Cheeso 特來部落格提醒我,目前該套件已經從 DotNetZip 1.3 Release (2008/2/5) 介紹至今 1.7 (2009/2/10) 已經滿一年了,DotNetZip 也有十足的進步。DotNet Zip Library 是我覺得 SharpZip 之外另一個比較好用的壓縮與解壓縮的類別庫。

Project Description

The Microsoft .NET Framework, starting with v2.0 for the desktop Framework and v3.5 for the Compact Framework, includes new base class libraries supporting compression within streams - both the Deflate and Gzip formats are supported. But the classes in the System.IO.Compression namespace are not directly useful for creating compressed zip archives. 
The built-in compression library is not able to read or write zip archive headers and other meta data.

This is a simple class library that provides ZIP file support.  Using this library, you can write .NET applications that read and write zip-format files, including files with passwords, Unicode filenames, and comments.  The library also supports ZIP64 and self-extracting archives. (支援建立 ZIP64 格式與自解壓縮檔案)

DotNetZip works with applications running on PCs with Windows.  There is a version of this library available for the .NET Compact Framework, too. (Winodws Mobile 或是 CE 上野有支援呢)

 

為減少組件大小分,可根據需求引用:

Ionic.Zlib.dll          77k   DeflateStream and ZlibCodec

Ionic.Zip.dll          335k   includes ZLIB and SFX

Ionic.Zip.Reduced.dll  130k   includes ZLIB but not SFX

Ionic.Zlib.CF.dll       66k   DeflateStream and ZlibCodec (Compact Framework)

Ionic.Zip.CF.dll       140k   includes ZLIB but not SFX (Compact Framework)

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 and streams. The main type is ZipFile, featuring methods like Add(), Extract() and Save(), string and int indexers on the entries of the zipfile, properties for password protection, unicode and codepage support, and ZIP64 behavior.

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?
As of version 1.7, the Ionic zip DLL is about 260k in size. The self-extracting stuff, added in v1.5 in June 2008, is optional, and amounts to about 190k of that.
The Compact-Framework version of the library is about 70k. There is just one DLL. There is no other pre-requisite. Does this library make self-extracting zip files?
Yes. As of v1.5, It can make self-extracting zip files. It also makes standard zip files. The self-extracting archives can either be Windows apps or command-line applications.

Are the zip files this library makes compatible with the Java.util.zip classes in the Java class library?
Yes. This library makes standard zip files.

Does the library support zero-length zip entries, zipfile comments, zip entry comments, zipping up empty directories, and password-protecting entries?
Yes

Does the library do AES 128 or 256 encryption?
No. It's an open request.

Does the library support Unicode filenames and comments?
Yes, as of September 2008, the library can create and read zip files that have Unicode (UTF-8) filenames and comments. You can also specify arbitrary code pages.

Can the library be used to read a zip file that has entries with filenames containing Chinese characters, produced by WinRAR?
Yes. To do this you would specify the "big5" code page (cp 950) when reading the zip.

 

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

There are numerous limitations to this library:

it does NOT support encryption, file comments, or double-byte chars in filenames.  (可支援雙位元字串的檔案名稱,包含 Big5)

it does NOT support file lengths greater than 0xffffffff. (可解決容量限制的問題)

it does not support "multi-disk archives." or "disk spanning"

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 The GUI tool for creating zips is pretty basic.

 

簡單範例:

   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:  }