Chilkat ZipEntry Overview
The Chilkat.ZipEntry class represents a single entry within a Chilkat.Zip object.
A ZipEntry can represent:
- A file already contained within an opened ZIP archive
- A referenced filesystem file that has not yet been compressed
- An in-memory data entry containing text or binary data
- A directory entry
ZipEntry objects provide access to metadata and content associated with a single ZIP entry, including:
- Stored filename and relative ZIP path
- Compressed and uncompressed sizes
- Compression method and compression level
- Encryption information
- CRC values
- Last-modified timestamps
- Directory/file status
ZipEntry objects are typically obtained from a Chilkat.Zip object using methods such as:
FirstEntryEntryAtEntryOfEntryMatchingEntryById
For example:
Chilkat.Zip zip = new Chilkat.Zip();
bool success = zip.OpenZip("example.zip");
Chilkat.ZipEntry entry = zip.FirstEntry();
ZIP Entry Types
The EntryType property indicates the current state and origin of the entry.
Possible values are:
| EntryType | Meaning |
|---|---|
| 0 | Mapped Entry — An entry already contained within an opened ZIP archive |
| 1 | File Entry — A referenced filesystem file awaiting compression |
| 2 | Data Entry — An in-memory entry containing uncompressed data |
| 3 | Null Entry — An entry that no longer exists |
| 4 | New Directory Entry — A directory entry |
When a ZIP archive is written using methods such as WriteZip or WriteToMemory, all entries become mapped entries (EntryType = 0).
Working with Entry Content
ZipEntry objects can be used to:
- Extract individual entries
- Inflate entry contents directly into memory
- Read text or binary content
- Append or replace data
- Access compressed ZIP entry bytes
For example, a text file entry can be unzipped directly into a string:
string txt = entry.UnzipToString(0,"utf-8");
Or extracted to disk:
success = entry.Extract("c:/output");
Modifying Entries
Entries can be modified in memory before writing the ZIP archive.
For example:
success = entry.AppendString("More text","utf-8");
If the entry is not already a Data Entry (EntryType = 2), Chilkat automatically converts it into an in-memory Data Entry before appending the new data.
For example:
- A mapped entry is inflated into memory
- A file entry loads the referenced filesystem file into memory
The entry then becomes an in-memory Data Entry containing the modified content.
Filesystem References vs ZIP Data
An important concept in the Chilkat.Zip and Chilkat.ZipEntry classes is the distinction between:
- Referenced filesystem files
- In-memory data entries
- Mapped ZIP entries
Methods such as AddFile, AppendFiles, and AppendFilesEx initially add references to files in the local filesystem. The files are not immediately read or compressed.
The actual file reading and compression occur later when the ZIP archive is written.
After writing the ZIP archive, the entries become mapped entries representing compressed data already stored within the ZIP.