Mon, 03 Apr 2006 10:26
Zip Library
---------------------------------
The Microsoft .NET Framework {v2.0 v3.0 v3.5} includes new base class
libraries supporting compression within streams - both the
Deflate and Gzip formats are supported. But the new-for-.NET2.0
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.
This is a simple class library that 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.
The Zip Format
---------------------------------
The zip format is described by PKWare, at
http://www.pkware.com/business_and_developers/developer/popups/appnote.txt
Every valid zipfile conforms to this specification. For
example, the spec says that for each compressed file contained
in the zip archive, the zipfile contains a byte array of
compressed data. (The byte array is something the DeflateStream
class can produce directly.) But the zipfile also contains
header and "directory" information - you might call this
"metadata". In other words, the zipfile must contain a list of
all the compressed files in the archive. The zipfile also
contains CRC checksums, and can also contain comments, and other
optional attributes for each file. These are things the
DeflateStream class, included in the .NET Framework Class
Library, does not read or write.
This Class Library
---------------------------------
The library included here depends on the DeflateStream class,
and extends it to support reading and writing of the metadata -
the header, CRC, and other optional data - defined or required
by the zip format spec.
The key object in the class library is the ZipFile class. The key methods on it:
- AddItem - adds a file or a directory to a zip archive
- AddDirectory - adds a directory to a zip archive
- AddFile - adds a file to a zip archive
- Extract - extract a single element from a zip file
- Read - static methods to read in an existing zipfile, for
later extraction
- Save - save a zipfile to disk
There is also a supporting class, called ZipEntry. Applications
can enumerate the entries in a ZipFile, via ZipEntry. There are
other supporting classes as well. Typically apps do not
directly interact with these other classes.
Using the Class Library
---------------------------------
Check the examples included in this package for simple apps that
show how to read and write zip files. The simplest way to
create a zipfile looks like this:
using(ZipFile zip= new ZipFile(NameOfZipFileTocreate))
{
zip.AddFile(filename);
zip.Save();
}
The simplest way to Extract all the entries from a zipfile looks
like this:
using (ZipFile zip = ZipFile.Read(NameOfExistingZipFile))
{
zip.ExtractAll(args[1]);
}
There are a number of other options for using the class
library. For example, you can read zip archives from streams,
or you can create (write) zip archives to streams. Check the
doc for complete information.
About Directory Paths
---------------------------------
One important note: the ZipFile.AddXxx methods add the file or
directory you specify, including the directory. In other words,
logic like this:
zip.AddFile("c:\\a\\b\\c\\Hello.doc");
zip.Save();
...will produce a zip archive that contains a single file, which
is stored with the relative directory information. When you
extract that file from the zip, either using this Zip library or
winzip or the built-in zip support in Windows, or some other
package, all those directories will be created, and the file
will be written into that directory hierarchy.
If you don't want that directory information in your archive,
then you need to either
(a) copy the file or files to be compressed into the local
directory
(b) change the applications current directory to where the file
resides, before adding it to the zipfile.
The latter involves a call to
System.IO.Directory.SetCurrentDirectory(),
before you call ZipFile.AddXxx().
See the doc:
http://msdn2.microsoft.com/en-us/library/system.io.directory.setcurrentdirectory.aspx
About the Help file
--------------------------------
The .chm file contains help generated from the code.
In some cases, Upon opening the .chm file for DotNetZipLib, the
help items tree loads, but the contents are empty. You may see
an Error: This program cannot display the webpage. If this
happens, it's probable that you encounter problem with Windows
protection of files downloaded from less trusted
location. Within Windows Explorer, right-click on the CHM file,
select properties, and Unblock it (button in lower part of
properties window).
License
--------
This software is released under the Microsoft Permissive License
of OCtober 2006. See the License.txt file for details.
About Other Intellectual Property
---------------------------------
I am no lawyer, but before using this library in your app, it
may be worth contacting PKWare for clarification on rights and
licensing. The specification for the zip format includes a
paragraph that reads:
PKWARE is committed to the interoperability and advancement of the
.ZIP format. PKWARE offers a free license for certain technological
aspects described above under certain restrictions and conditions.
However, the use or implementation in a product of certain technological
aspects set forth in the current APPNOTE, including those with regard to
strong encryption or patching, requires a license from PKWARE. Please
contact PKWARE with regard to acquiring a license.
Contact pkware at: zipformat@pkware.com
This example also uses a CRC utility class, in modified form,
that was published on the internet without an explicit license.
You can find the original CRC class at:
http://www.vbaccelerator.com/home/net/code/libraries/CRC32/Crc32_zip_CRC32_CRC32_cs.asp
Pre-requisites
---------------------------------
to run:
.NET Framework 2.0 or later
to build:
.NET Framework 2.0 SDK or later
or
Visual Studio 2005 or later
Building
---------------------------------
To build this example,
1. extract the contents of this zip into a new directory.
2. be sure the .NET 2.0 SDK and .NET 2.0 runtime directories
are on your path. These are typically
C:\Program Files\Microsoft.NET\SDK\v2.0\bin
and
c:\WINDOWS\Microsoft.NET\Framework\v2.0.50727
3. open a CMD prompt and CD to the zip\Library directory.
4. nmake
5. To build the examples, cd ..\Examples and type nmake again
Building the Help File
--------------------------------------------
If you want to build the helpfile, you need the SandCastle
helpfile builder. Use the DotNetZip.shfb file with SandCastle.
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
and, I'm sure, many others
But it is a good basic library for reading and writing zipfiles
in .NET applications..
And yes, the zipfile that this example is shipped in, was
produced by this example library.
See Also
----------------------------
没有合适的资源?快使用搜索试试~ 我知道了~
温馨提示
DotNetZip编码源码 前几天发布了[DotNetZip解决文件名称中文字符不显示的问题],解决了中文名称的显示问题,从几位热心网友的回帖来看,是希望能支持多种编码!! 这两天抽了点时间,将源代码修改了一下,使其能够支持多种编码!! 当然也可以不指定编码,这时将使用默认编码:GB2312!! 测试: 压缩的后的路径是 testzip/bin/debug/2/11.zip 解压是将 testzip/bin/debug/2/11.zip解压到/bin/debug/3/目录里
资源推荐
资源详情
资源评论
收起资源包目录
DotNetZip编码源码 (174个子文件)
ResolveAssemblyReference.cache 5KB
ResolveAssemblyReference.cache 3KB
testzip.csproj.GenerateResource.Cache 847B
ZipFile.cs 67KB
ZipEntry.cs 45KB
ZipDirEntry.cs 8KB
UnZip.cs 6KB
Shared.cs 5KB
Crc32.cs 4KB
Form1.Designer.cs 4KB
Resources.Designer.cs 3KB
Form1.cs 3KB
CreateZip.cs 3KB
ZipIt.cs 2KB
ZipDir.cs 2KB
ReadZip.cs 2KB
AssemblyInfo.cs 1KB
AssemblyInfo.cs 1KB
AssemblyInfo.cs 1KB
AssemblyInfo.cs 1KB
AssemblyInfo.cs 1KB
AssemblyInfo.cs 1KB
AssemblyInfo.cs 1KB
Settings.Designer.cs 1KB
Program.cs 468B
Constants.cs 408B
#UnZip.cs# 5KB
Library.csproj 4KB
testzip.csproj 4KB
CreateZip.csproj 2KB
ReadZip.csproj 2KB
ZipDir.csproj 2KB
ZipIt.csproj 2KB
UnZip.csproj 2KB
Thumbs.db 6KB
Ionic.Utils.Zip.dll 30KB
Ionic.Utils.Zip.dll 30KB
Ionic.Utils.Zip.dll 30KB
Ionic.Utils.Zip.dll 30KB
Ionic.Utils.Zip.dll 30KB
Ionic.Utils.Zip.dll 30KB
Ionic.Utils.Zip.dll 30KB
Ionic.Utils.Zip.dll 30KB
Ionic.Utils.Zip.dll 10KB
testzip.vshost.exe 14KB
testzip.exe 10KB
testzip.exe 10KB
UnZip.exe 8KB
UnZip.exe 8KB
CreateZip.exe 6KB
ZipIt.exe 6KB
CreateZip.exe 6KB
ZipIt.exe 6KB
ZipDir.exe 6KB
ZipDir.exe 6KB
ReadZip.exe 5KB
ReadZip.exe 5KB
北京地铁地图.jpg 358KB
北京地铁地图.jpg 358KB
桃花.jpg 31KB
桃花.jpg 31KB
redleaf.jpg 3KB
redleaf.jpg 3KB
LastBuild.log 275KB
makefile 605B
testzip.vshost.exe.manifest 490B
Ionic.Utils.Zip.pdb 80KB
Ionic.Utils.Zip.pdb 80KB
Ionic.Utils.Zip.pdb 80KB
Ionic.Utils.Zip.pdb 80KB
Ionic.Utils.Zip.pdb 80KB
Ionic.Utils.Zip.pdb 80KB
Ionic.Utils.Zip.pdb 80KB
Ionic.Utils.Zip.pdb 80KB
testzip.pdb 24KB
testzip.pdb 24KB
UnZip.pdb 16KB
UnZip.pdb 16KB
ZipIt.pdb 14KB
CreateZip.pdb 14KB
ZipIt.pdb 14KB
CreateZip.pdb 14KB
ReadZip.pdb 14KB
ReadZip.pdb 14KB
ZipDir.pdb 14KB
ZipDir.pdb 14KB
testzip.Properties.Resources.resources 180B
testzip.Form1.resources 180B
Form1.resx 6KB
Resources.resx 5KB
Settings.settings 249B
DotNetZip.shfb 2KB
DotNetZip.sln 4KB
DotNetZip.suo 52KB
ZipFile.cs.tfs-base 61KB
ZipEntry.cs.tfs-base 42KB
Setup.vdproj.tfs-base 31KB
ZipDirEntry.cs.tfs-base 8KB
Readme.txt.tfs-base 7KB
UnZip.cs.tfs-base 6KB
共 174 条
- 1
- 2
资源评论
- ME_Rz2013-05-18还好,可以学习一下,但有BUG
ss_geng
- 粉丝: 319
- 资源: 3220
上传资源 快速赚钱
- 我的内容管理 展开
- 我的资源 快来上传第一个资源
- 我的收益 登录查看自己的收益
- 我的积分 登录查看自己的积分
- 我的C币 登录后查看C币余额
- 我的收藏
- 我的下载
- 下载帮助
安全验证
文档复制为VIP权益,开通VIP直接复制
信息提交成功