These are the highest level classes in the C1Zip library. They allow you to create and manage zip files. Using zip files to store application data provides the following benefits:
•You can consolidate many files into one, making application deployment easier.
•You can compress the data, saving disk space and network bandwidth.
•The zip format is an open standard, supported by many popular applications.
C1ZipFile Class
The C1ZipFile class encapsulates a zip file. After you create a C1ZipFile object, you can attach it to an existing zip file or tell it to create a new empty zip file for you.
The code below creates a zip file called sources.zip and adds all files with a "cs" extension to the zip file:
// get path for zip file and files to compress
string path = Application.ExecutablePath;
int pos = path.IndexOf(@"\bin");
path = path.Substring(0, pos + 1);
// create a zip file
C1ZipFile zip = new C1ZipFile();
zip.Create(path + "source.zip");
// add all files with extension cs to the zip file
foreach (string fileName in Directory.GetFiles(path, "*.cs"))
zip.Entries.Add(fileName);
// show result
foreach (C1ZipEntry ze in zip.Entries)
{
Console.WriteLine("{0} {1:#,##0} {2:#,##0}",
ze.FileName, ze.SizeUncompressed, ze.SizeCompressed);
}
C1ZipEntryCollection Class
After you have created or opened a zip file, use the Entries collection to inspect the contents of the zip file, or to add, expand, and delete entries. For example:
myZip.Entries.Add(stream1, "MyData.txt")
myZip.Entries.Add(stream2, "MyData.xml")
Dim zipEntry As C1ZipEntry
For Each zipEntry In myZip.Entries
Console.WriteLine(zipEntry.FileName)
Next zipEntry
•C#
myZip.Entries.Add(stream1, "MyData.txt");
myZip.Entries.Add(stream2, "MyData.doc");
foreach (C1ZipEntry zipEntry in myZip.Entries)
Debug.WriteLine(zipEntry.FileName);
C1ZipEntry Class
The C1ZipEntry class exposes properties and methods that describe each entry, including its original file name, size, compressed size, and so on. It also has a OpenReader method that returns a stream object, so you can read the entry contents without expanding it first.