PckPacker
Writes files and removal entries into a PCK with explicit finalization.
Sequence: PckStart → AddFile or AddFileFromBuffer → Flush. Check Error at every step. The packer copies bytes; it does not perform project-resource import or export. Use ZipPacker for ZIP archives.
This example creates a pack with one UTF-8 file; the output directory must exist. Writing is not atomic: a partial file is not automatically removed on failure.
using System.Text;
using Reckfell;
public static class PackBuildExample
{
public static Error WriteTextPack(string outputPath, string text)
{
using var pack = new PckPacker();
Error error = pack.PckStart(outputPath);
if (error != Error.Ok)
return error;
error = pack.AddFileFromBuffer("asset://Extra/message.txt", Encoding.UTF8.GetBytes(text));
if (error != Error.Ok)
return error;
return pack.Flush();
}
}See the PCK/ZIP guide for mounting, patch order and caching.
Declarations checked against C# SDK 1.0.0. Expand a name to see declarations and documentation.
Constructors1
PckPackerConstructor
public PckPacker();Creates a packer with no open file. Call PckStart, add files and explicitly check Flush. Use using to dispose the packer.
Methods6
AddFileError
public Error AddFile(string targetPath, string sourcePath, bool encrypt = false);Reads sourcePath and immediately writes its bytes to the open pack at logical targetPath. Does not import source models, discover dependencies or export a project. Requires successful PckStart; finalize additions with Flush.
| Name | Type | Default |
|---|---|---|
targetPath | string | — |
sourcePath | string | — |
encrypt | bool | false |
targetPathLogical path inside the pack. An optional asset:// prefix is stripped when written; this is not the output PCK filename.
sourcePathPath to an existing readable file through FileAccess. Its current bytes are copied into the pack, not a reference to the file.
encryptEncrypt this file payload with the PckStart key. Does not change directory encryption.
ErrorError.Ok on success; otherwise an error code. Check before the next step; failure does not imply automatic deletion of a partial file.
AddFileFromBuffer2 overloads
public Error AddFileFromBuffer(string targetPath, byte[] data, bool encrypt = false);Immediately writes data bytes to the open pack at targetPath. Changing the source array after return does not alter bytes already written. Does not automatically serialize a Variant or Resource. Requires successful PckStart; finalize additions with Flush.
| Name | Type | Default |
|---|---|---|
targetPath | string | — |
data | byte[] | — |
encrypt | bool | false |
targetPathLogical path inside the pack. An optional asset:// prefix is stripped when written; this is not the output PCK filename.
dataPayload bytes. Choose an encoding for text, for example Encoding.UTF8.GetBytes(text). The span overload requires an explicit encrypt argument.
encryptEncrypt this file payload with the PckStart key. Does not change directory encryption.
ErrorError.Ok on success; otherwise an error code. Check before the next step; failure does not imply automatic deletion of a partial file.
public Error AddFileFromBuffer(string targetPath, ReadOnlySpan<byte> data, bool encrypt);Immediately writes data bytes to the open pack at targetPath. Changing the source array after return does not alter bytes already written. Does not automatically serialize a Variant or Resource. Requires successful PckStart; finalize additions with Flush.
| Name | Type | Default |
|---|---|---|
targetPath | string | — |
data | ReadOnlySpan<byte> | — |
encrypt | bool | — |
targetPathLogical path inside the pack. An optional asset:// prefix is stripped when written; this is not the output PCK filename.
dataPayload bytes. Choose an encoding for text, for example Encoding.UTF8.GetBytes(text). The span overload requires an explicit encrypt argument.
encryptEncrypt this file payload with the PckStart key. Does not change directory encryption.
ErrorError.Ok on success; otherwise an error code. Check before the next step; failure does not imply automatic deletion of a partial file.
AddFileRemovalError
public Error AddFileRemoval(string targetPath);Adds a logical-path removal entry to the open PCK. Does not change the filesystem immediately: removal applies when the completed pack is mounted. A removal entry applies even with LoadResourcePack(..., replaceFiles: false). It neither deletes a physical disk file nor releases an already loaded Resource.
| Name | Type | Default |
|---|---|---|
targetPath | string | — |
targetPathLogical path inside the pack. An optional asset:// prefix is stripped when written; this is not the output PCK filename.
ErrorError.Ok on success; otherwise an error code. Check before the next step; failure does not imply automatic deletion of a partial file.
FlushError
public Error Flush(bool verbose = false);Writes the directory of added files and closes the current PCK. Call explicitly and check Error; another pack requires PckStart. Disposing an open packer also finalizes it, but does not return the Flush result to the caller. This is not an atomic-write or power-loss durability guarantee.
| Name | Type | Default |
|---|---|---|
verbose | bool | false |
verboseWhen true, log added-file details during finalization. Does not change pack contents.
ErrorError.Ok on success; otherwise an error code. Check before the next step; failure does not imply automatic deletion of a partial file.
PckStartError
public Error PckStart(string pckPath, int alignment = 32, string key = "0000000000000000000000000000000000000000000000000000000000000000", bool encryptDirectory = false);Opens the output for writing and starts a new PCK. Does not append .pck; an existing file can be overwritten. Finish the current pack before starting another. The key is validated even when encryption is disabled.
| Name | Type | Default |
|---|---|---|
pckPath | string | — |
alignment | int | 32 |
key | string | "0000000000000000000000000000000000000000000000000000000000000000" |
encryptDirectory | bool | false |
pckPathOutput file path, such as user://extra.pck, or an absolute path. The parent directory must exist.
alignmentPositive alignment in bytes; defaults to 32. Zero and negative values are rejected.
keyExactly 64 hexadecimal characters encoding a 32-byte AES-256 key, not a password. The default zero key is not secret. Reading encrypted data requires the matching loader key.
encryptDirectoryEncrypt the pack directory. Does not enable encryption of every file payload; each addition has its own encrypt flag.
ErrorError.Ok on success; otherwise an error code. Check before the next step; failure does not imply automatic deletion of a partial file.