ZipPacker
Write ZIP records with explicit archive finalization.
Create an owned ZipPacker, select CompressionLevel, check Open, then StartFile → WriteFile → CloseFile per entry and finally Close. WriteFile accepts bytes rather than a source-file path; encode text as UTF-8 explicitly. Dispose releases the object, but explicit Close is needed to inspect archive-finalization status.
Create replaces the destination file, Addinzip appends records to an existing ZIP and Createafter starts a new ZIP after existing file contents. Addinzip does not replace a same-name entry: it creates duplicates and ZipReader reads the first match. Not a transactional file update.
Level -1 or 0..9 affects later StartFile and AddDirectory calls rather than an already open entry. In the current implementation None=0 still uses ZIP method Deflate with level 0 rather than Store. Reader GetCompressionLevel does not recover the setting: for example 0 and 3 can be reported as category 6. Performance and compression ratio were not benchmarked.
AddDirectory writes a directory record and metadata rather than copying a filesystem tree. StartFile can add the immediate parent record, not every ancestor. Use relative slash-separated archive names. Permissions are ZIP metadata rather than filesystem chmod; modifiedTime is UNIX seconds with 0 meaning current time. The current implementation adds the current timezone offset of the host rather than the historical offset for that timestamp.
Small Windows archives and independent Python reading were tested. ZIP64, crash recovery, corrupt input/disk failures, permission application during extraction and other platforms remain unaccepted.
Declarations checked against C# SDK 1.0.0. Expand a name to see declarations and documentation.
Constructors1
ZipPackerConstructor
public ZipPacker();Creates an owned packer without an open file and CompressionLevel=-1. Compression can be set before Open. Check Error when finishing entries/archive, then dispose the object.
Properties1
CompressionLevelProperty
public int CompressionLevel { get; set; }Setting -1 or 0..9 for the next opened entry, default -1. Does not change an already started record and persists after Close. None=0 here means Deflate level 0 rather than ZIP Store. Invalid levels are diagnosed and rejected; settings guarantee no particular speed/size.
Methods10
AddDirectoryError
public Error AddDirectory(string path, FileAccess.UnixPermissionFlags permissions = FileAccess.UnixPermissionFlags.ExecuteOther | FileAccess.UnixPermissionFlags.ReadOther | FileAccess.UnixPermissionFlags.ExecuteGroup | FileAccess.UnixPermissionFlags.ReadGroup | FileAccess.UnixPermissionFlags.ExecuteOwner | FileAccess.UnixPermissionFlags.WriteOwner | FileAccess.UnixPermissionFlags.ReadOwner, ulong modifiedTime = 0);Adds a directory record, appending / when needed, and immediately closes it. Scans no filesystem and adds no ancestor chain. Repeating a cached path in the same session is rejected; existing archive directories are not automatically loaded into that cache. Call between file entries and check Error.
| Name | Type | Default |
|---|---|---|
path | string | — |
permissions | FileAccess.UnixPermissionFlags | FileAccess.UnixPermissionFlags.ExecuteOther | FileAccess.UnixPermissionFlags.ReadOther | FileAccess.UnixPermissionFlags.ExecuteGroup | FileAccess.UnixPermissionFlags.ReadGroup | FileAccess.UnixPermissionFlags.ExecuteOwner | FileAccess.UnixPermissionFlags.WriteOwner | FileAccess.UnixPermissionFlags.ReadOwner |
modifiedTime | ulong | 0 |
pathExact internal ZIP name, normally relative with /; not a local destination or source-data path.
permissionsUNIX permission flags stored as ZIP metadata rather than applied to the filesystem. Default 0644 for files and 0755 for directories; 0 also selects that default rather than no permissions.
modifiedTimeUNIX seconds rather than milliseconds; 0 means current time rather than the 1970 epoch. Written using the current timezone offset of the host and ZIP timestamp precision.
ErrorError.Ok on success; otherwise a stage error rather than a guarantee of unchanged file contents.
CloseError
public Error Close();Finalizes the ZIP central directory and closes the file; check Error.Ok before publishing the result. The current library also finishes an open entry, while explicit CloseFile lets you inspect that result separately. Retains CompressionLevel and clears the directory cache on success. Re-closing a closed session is diagnosed.
ErrorError.Ok on success; otherwise a stage error rather than a guarantee of unchanged file contents.
CloseFileError
public Error CloseFile();Finishes the current entry while leaving the archive open for another. AddDirectory already closes its record. Check Error.Ok; calling without a current entry is not a successful operation.
ErrorError.Ok on success; otherwise a stage error rather than a guarantee of unchanged file contents.
GetCompressionLevelint
public int GetCompressionLevel();Reads the stored packer setting rather than a header category from an existing record. Requires no open archive.
intStored packer setting -1 or 0..9.
OpenError
public Error Open(string path, ZipPacker.ZipAppend append = ZipPacker.ZipAppend.Create);Opens a destination using append mode; default Create replaces the file. Addinzip appends records and Createafter starts a separate ZIP after existing bytes. Calls Close on a previous session without directly forwarding its failure: close explicitly. Prepare the destination parent directory first.
| Name | Type | Default |
|---|---|---|
path | string | — |
append | ZipPacker.ZipAppend | ZipPacker.ZipAppend.Create |
pathFileAccess archive path; writing requires a writable existing directory. Not an internal ZIP record name.
appendCreate=0 replaces; Createafter=1 adds a new ZIP after bytes; Addinzip=2 appends existing-ZIP records without name replacement.
ErrorError.Ok on success; otherwise a stage error rather than a guarantee of unchanged file contents.
SetCompressionLevelvoid
public void SetCompressionLevel(int compressionLevel);Sets CompressionLevel for later records: -1 or 0..9. Allowed before Open; does not recompress an already open record.
| Name | Type | Default |
|---|---|---|
compressionLevel | int | — |
compressionLevel-1 for default or integer 0..9, applied to later records. Level 0 does not switch the ZIP method to Store in the current implementation.
StartFile2 overloads
public Error StartFile(string path);Starts a new path-named record inside the open archive rather than reading a source file. Can add its immediate parent record with 0755. Uses the compression setting at call time. A repeated name creates a duplicate rather than replacement. Finish the preceding record explicitly; permissions/modifiedTime set this record metadata. This overload supplies 0644 and modifiedTime=0 and is not SDK-obsolete.
| Name | Type | Default |
|---|---|---|
path | string | — |
pathExact internal ZIP name, normally relative with /; not a local destination or source-data path.
ErrorError.Ok on success; otherwise a stage error rather than a guarantee of unchanged file contents.
public Error StartFile(string path, FileAccess.UnixPermissionFlags permissions = FileAccess.UnixPermissionFlags.ReadOther | FileAccess.UnixPermissionFlags.ReadGroup | FileAccess.UnixPermissionFlags.WriteOwner | FileAccess.UnixPermissionFlags.ReadOwner, ulong modifiedTime = 0);Starts a new path-named record inside the open archive rather than reading a source file. Can add its immediate parent record with 0755. Uses the compression setting at call time. A repeated name creates a duplicate rather than replacement. Finish the preceding record explicitly; permissions/modifiedTime set this record metadata.
| Name | Type | Default |
|---|---|---|
path | string | — |
permissions | FileAccess.UnixPermissionFlags | FileAccess.UnixPermissionFlags.ReadOther | FileAccess.UnixPermissionFlags.ReadGroup | FileAccess.UnixPermissionFlags.WriteOwner | FileAccess.UnixPermissionFlags.ReadOwner |
modifiedTime | ulong | 0 |
pathExact internal ZIP name, normally relative with /; not a local destination or source-data path.
permissionsUNIX permission flags stored as ZIP metadata rather than applied to the filesystem. Default 0644 for files and 0755 for directories; 0 also selects that default rather than no permissions.
modifiedTimeUNIX seconds rather than milliseconds; 0 means current time rather than the 1970 epoch. Written using the current timezone offset of the host and ZIP timestamp precision.
ErrorError.Ok on success; otherwise a stage error rather than a guarantee of unchanged file contents.
WriteFile2 overloads
public Error WriteFile(byte[] data);Writes bytes into the current open entry. Multiple calls append successive chunks; infers no source path or encoding. Use bounded chunks within your memory budget. Check Error from this call rather than only a later Close.
| Name | Type | Default |
|---|---|---|
data | byte[] | — |
dataCurrent-entry bytes; explicitly encode strings first, for example as UTF-8. An array/ReadOnlySpan is not a file path.
ErrorError.Ok on success; otherwise a stage error rather than a guarantee of unchanged file contents.
public Error WriteFile(ReadOnlySpan<byte> data);Writes bytes into the current open entry. Multiple calls append successive chunks; infers no source path or encoding. Use bounded chunks within your memory budget. Check Error from this call rather than only a later Close.
| Name | Type | Default |
|---|---|---|
data | ReadOnlySpan<byte> | — |
dataCurrent-entry bytes; explicitly encode strings first, for example as UTF-8. An array/ReadOnlySpan is not a file path.
ErrorError.Ok on success; otherwise a stage error rather than a guarantee of unchanged file contents.
ZipPacker.CompressionLevelEnum
| Value | Description |
|---|---|
Best = 9 | Deflate level 9 for subsequent records. Guarantees neither minimum size for every input nor a particular packing time. |
Default = -1 | Level -1 selects the zlib default for subsequent records. Not a value ZipReader must recover for that record. |
Fast = 1 | Deflate level 1 for subsequent records. Speed and size depend on data; changes no current entry. |
None = 0 | Level 0. The current packer keeps ZIP method Deflate with level 0 rather than method Store. Verified from the produced archive header; promises no specific speed. |
ZipPacker.ZipAppend
| Value | Description |
|---|---|
Addinzip = 2 | 2 appends records to an existing ZIP. A repeated name adds another entry rather than replacing the old one. |
Create = 0 | 0 creates a ZIP by replacing the destination file. Not the mode for retaining an existing ZIP. |
Createafter = 1 | 1 creates a new ZIP after existing file contents rather than appending records into an earlier ZIP like Addinzip. |