ZipReader
Read ZIP entries into memory without automatic disk extraction.
Create an owned ZipReader, check Open, then use GetFiles/FileExists/ReadFile and explicit Close. A RefCounted object rather than Resource; dispose after use. Open replaces a previous archive by closing it before the next attempt: failure does not preserve the old session.
GetFiles returns a flat list of actual records including slash-terminated directories and duplicate names. Virtual parent directories are not synthesized. ReadFile loads the whole decompressed entry into byte[] rather than a stream; an empty result can mean an empty file or a diagnosed failure. The method creates no files on disk.
ReadFile uses engine Unicode path lookup while FileExists/GetCompressionLevel use minizip lookup, so Unicode case-insensitive matching can differ. Use exact names from GetFiles. Duplicate names are not versions: ReadFile selects the first match. GetCompressionLevel derives a category from ZIP flags rather than recovering the original packer setting.
Windows headless checks and independent Python reads covered our small archives. Corrupt/huge/ZIP64 input, disk extraction, memory limits and cross-platform behavior were not accepted. Names from an external archive are not ready-made safe destination paths for a custom extractor.
Declarations checked against C# SDK 1.0.0. Expand a name to see declarations and documentation.
Constructors1
ZipReaderConstructor
public ZipReader();Creates an owned closed reader without an open file. Use entry operations after successful Open; check Close explicitly, then dispose the object.
Methods6
CloseError
public Error Close();Closes a successfully opened archive. Check Error.Ok; closing an already closed object produces a diagnostic rather than an idempotent success. Does not dispose the RefCounted object.
ErrorError.Ok on success; otherwise a stage error rather than a guarantee of unchanged file contents.
FileExistsbool
public bool FileExists(string path, bool caseSensitive = true);Tests locating and opening an entry rather than content integrity. Case-sensitive by default; a directory requires its actual slash-terminated name. caseSensitive=false uses minizip lookup and can disagree with ReadFile for Unicode.
| Name | Type | Default |
|---|---|---|
path | string | — |
caseSensitive | bool | true |
pathExact internal ZIP name, normally relative with /; not a local destination or source-data path.
caseSensitivetrue is case-sensitive by default. false uses different Unicode lookup implementations in ReadFile versus FileExists/GetCompressionLevel; prefer exact GetFiles names.
booltrue when an entry can be located and opened; not CRC validation.
GetCompressionLevelint
public int GetCompressionLevel(string path, bool caseSensitive = true);Returns a minizip header-flag category, typically 1, 2, 6 or 9, or -1 when unavailable. Not the original packer setting: our level-0 or level-3 records return 6. caseSensitive=false uses the FileExists lookup path rather than ReadFile.
| Name | Type | Default |
|---|---|---|
path | string | — |
caseSensitive | bool | true |
pathExact internal ZIP name, normally relative with /; not a local destination or source-data path.
caseSensitivetrue is case-sensitive by default. false uses different Unicode lookup implementations in ReadFile versus FileExists/GetCompressionLevel; prefer exact GetFiles names.
intZIP flag category rather than exact original level; -1 when unavailable.
GetFilesstring[]
public string[] GetFiles();Returns a new string[] of actual record names in archive traversal order including slash-terminated directories and duplicates. Extracts no files and synthesizes no missing parent records. Array edits change no archive.
string[]New array of actual entry names including directories and duplicates.
OpenError
public Error Open(string path);Opens a ZIP file through FileAccess for reading. Closes a previous archive first; a new failure does not preserve it. Returns Error.Ok/Failed and does not validate every entry CRC at open time.
| Name | Type | Default |
|---|---|---|
path | string | — |
pathFileAccess archive path; writing requires a writable existing directory. Not an internal ZIP record name.
ErrorError.Ok on success; otherwise a stage error rather than a guarantee of unchanged file contents.
ReadFilebyte[]
public byte[] ReadFile(string path, bool caseSensitive = true);Reads the entire decompressed entry into an independent byte[]. Checks read errors and completion CRC; failure returns an empty array with a diagnostic. An empty entry also returns an empty array. Allocates from declared size; the code checks INT_MAX but large/ZIP64 archives were not accepted in this review. Extracts nothing to disk. Selects the first duplicate name.
| Name | Type | Default |
|---|---|---|
path | string | — |
caseSensitive | bool | true |
pathExact internal ZIP name, normally relative with /; not a local destination or source-data path.
caseSensitivetrue is case-sensitive by default. false uses different Unicode lookup implementations in ReadFile versus FileExists/GetCompressionLevel; prefer exact GetFiles names.
byte[]New decompressed byte array; empty for an empty record or a diagnosed failure.