reckfellENGINE

ZipPacker

Write ZIP records with explicit archive finalization.

On this page
class ZipPackerReckfellSharpInherits RefCounted

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
# ZipPacker
C#
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
# CompressionLevel
C#
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
# AddDirectory
C#
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.

Parameters
NameTypeDefault
pathstring—
permissionsFileAccess.UnixPermissionFlagsFileAccess.UnixPermissionFlags.ExecuteOther | FileAccess.UnixPermissionFlags.ReadOther | FileAccess.UnixPermissionFlags.ExecuteGroup | FileAccess.UnixPermissionFlags.ReadGroup | FileAccess.UnixPermissionFlags.ExecuteOwner | FileAccess.UnixPermissionFlags.WriteOwner | FileAccess.UnixPermissionFlags.ReadOwner
modifiedTimeulong0
path

Exact internal ZIP name, normally relative with /; not a local destination or source-data path.

permissions

UNIX 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.

modifiedTime

UNIX 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.

Returns Error

Error.Ok on success; otherwise a stage error rather than a guarantee of unchanged file contents.

CloseError
# Close
C#
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.

Returns Error

Error.Ok on success; otherwise a stage error rather than a guarantee of unchanged file contents.

CloseFileError
# CloseFile
C#
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.

Returns Error

Error.Ok on success; otherwise a stage error rather than a guarantee of unchanged file contents.

GetCompressionLevelint
# GetCompressionLevel
C#
public int GetCompressionLevel();

Reads the stored packer setting rather than a header category from an existing record. Requires no open archive.

Returns int

Stored packer setting -1 or 0..9.

OpenError
# Open
C#
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.

Parameters
NameTypeDefault
pathstring—
appendZipPacker.ZipAppendZipPacker.ZipAppend.Create
path

FileAccess archive path; writing requires a writable existing directory. Not an internal ZIP record name.

append

Create=0 replaces; Createafter=1 adds a new ZIP after bytes; Addinzip=2 appends existing-ZIP records without name replacement.

Returns Error

Error.Ok on success; otherwise a stage error rather than a guarantee of unchanged file contents.

SetCompressionLevelvoid
# SetCompressionLevel
C#
public void SetCompressionLevel(int compressionLevel);

Sets CompressionLevel for later records: -1 or 0..9. Allowed before Open; does not recompress an already open record.

Parameters
NameTypeDefault
compressionLevelint—
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
# StartFile · 1/2
C#
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.

Parameters
NameTypeDefault
pathstring—
path

Exact internal ZIP name, normally relative with /; not a local destination or source-data path.

Returns Error

Error.Ok on success; otherwise a stage error rather than a guarantee of unchanged file contents.

# StartFile · 2/2
C#
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.

Parameters
NameTypeDefault
pathstring—
permissionsFileAccess.UnixPermissionFlagsFileAccess.UnixPermissionFlags.ReadOther | FileAccess.UnixPermissionFlags.ReadGroup | FileAccess.UnixPermissionFlags.WriteOwner | FileAccess.UnixPermissionFlags.ReadOwner
modifiedTimeulong0
path

Exact internal ZIP name, normally relative with /; not a local destination or source-data path.

permissions

UNIX 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.

modifiedTime

UNIX 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.

Returns Error

Error.Ok on success; otherwise a stage error rather than a guarantee of unchanged file contents.

WriteFile2 overloads
# WriteFile · 1/2
C#
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.

Parameters
NameTypeDefault
databyte[]—
data

Current-entry bytes; explicitly encode strings first, for example as UTF-8. An array/ReadOnlySpan is not a file path.

Returns Error

Error.Ok on success; otherwise a stage error rather than a guarantee of unchanged file contents.

# WriteFile · 2/2
C#
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.

Parameters
NameTypeDefault
dataReadOnlySpan<byte>—
data

Current-entry bytes; explicitly encode strings first, for example as UTF-8. An array/ReadOnlySpan is not a file path.

Returns Error

Error.Ok on success; otherwise a stage error rather than a guarantee of unchanged file contents.

ZipPacker.CompressionLevelEnum

ValueDescription
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

ValueDescription
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.

Reckfell Engine documentationBack to top ↑
QUICK LINKSGetting startedEntity hierarchyC# & .NET 10Scenes and prefabs
Reckfell guides and full API K
reckfellENGINE
RECKFELL ACCOUNT

Sign in

Sign in to your Reckfell account.

One account for the entire Reckfell platform.