C1Zip Fundamentals > High Level: C1ZipFile, C1ZipEntry and C1ZipEntryCollection Classes |
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:
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:
C# |
Copy Code
|
---|---|
// Create a C1ZipFile object. C1ZipFile myZip = new C1ZipFile(); // Create a new (empty) zip file. myZip.Create("New.zip"); // Open an existing zip file. myZip.Open("Old.zip"); |
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:
C# |
Copy Code
|
---|---|
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 an OpenReader method that returns a stream object, so you can read the entry contents without expanding it first.