vael:archive
Hardened archive creation, listing, reading, and extraction (tar, tar.gz,
tar.zst, zip).
Available in the vjs (vaeljs) runtime with both synchronous and async
worker-thread APIs (create, extract, list, readEntry); vjs-lite
(vaeljs-lite) exposes the synchronous APIs only. Never installed on
globalThis — import explicitly from "vael:archive".
Enforces path-traversal rejection, symlink/hardlink/special-entry blocking,
bounded streaming decompression, and compression-bomb ratio detection
(VAEL_ARCHIVE_ZIP_BOMB).
import ... from "vael:archive"
vael-archive (enabled by default in vaeljs-core and vaeljs-lite-core)create, extract, list, readEntry) are V8-only (vjs); vjs-lite exposes the 8 synchronous exports (detectFormat, packBytesSync, unpackBytesSync, listSync, readEntrySync, extractSync, createSync, ArchiveError).Example
Section titled “Example”import { detectFormat, packBytesSync, unpackBytesSync } from "vael:archive";
const bytes = packBytesSync( [{ path: "pkg/hello.txt", data: "hello archive" }], { format: "tar.gz" },);console.log(detectFormat(bytes)); // "tar.gz"const entries = unpackBytesSync(bytes);console.log(entries[0].path, entries[0].size);detectFormatv0.0.0-alpha.2ArchiveFormat from leading archive magic bytes or a filename extension (.tar, .tar.gz, .tgz, .tar.zst, .tzst, .zip).packBytesSyncv0.0.0-alpha.2tar, tar.gz, tar.zst, or zip byte buffer.unpackBytesSyncv0.0.0-alpha.2UnpackedEntry items.listvjs onlyv0.0.0-alpha.2listSyncv0.0.0-alpha.2readEntryvjs onlyv0.0.0-alpha.2readEntrySyncv0.0.0-alpha.2extractvjs onlyv0.0.0-alpha.2destDir with symlink guards, canonical containment checks, and atomic overwrite policy.extractSyncv0.0.0-alpha.2destDir with symlink guards, canonical containment checks, and atomic overwrite policy.createvjs onlyv0.0.0-alpha.2destPath from host files or directories without following symlinks, writing via a sibling temp...createSyncv0.0.0-alpha.2destPath from host files or directories without following symlinks, writing via a sibling temp...ArchiveLimitsv0.0.0-alpha.2PackEntryv0.0.0-alpha.2packBytesSync().PackOptionsv0.0.0-alpha.2packBytesSync().UnpackOptionsv0.0.0-alpha.2unpackBytesSync(), list(), listSync(), readEntry(), and readEntrySync().UnpackedEntryv0.0.0-alpha.2unpackBytesSync().ArchiveEntryInfov0.0.0-alpha.2list() and listSync().ExtractOptionsv0.0.0-alpha.2extract() and extractSync().ExtractResultv0.0.0-alpha.2extract() and extractSync().CreateSourcev0.0.0-alpha.2create() and createSync().CreateOptionsv0.0.0-alpha.2create() and createSync().CreateResultv0.0.0-alpha.2create() and createSync().Functions
Section titled “Functions”detectFormat
Section titled “detectFormat”export function detectFormat(input: Uint8Array | string): ArchiveFormat | null;
Detect an ArchiveFormat from leading archive magic bytes or a filename
extension (.tar, .tar.gz, .tgz, .tar.zst, .tzst, .zip).
| Name | Type | Description |
|---|---|---|
input | Uint8Array | string | Raw leading archive bytes or a file path/name string. |
TypeError— wheninputis neither aUint8Arraynor a string.
packBytesSync
Section titled “packBytesSync”export function packBytesSync(entries: readonly PackEntry[], options: PackOptions): Uint8Array;
Synchronously pack in-memory entries into a tar, tar.gz, tar.zst, or
zip byte buffer.
Validates all entry paths, rejects traversal segments and duplicate paths, and enforces default archive limits.
| Name | Type | Description |
|---|---|---|
entries | readonly PackEntry[] | Entries to pack into the archive. |
options | PackOptions | Format and optional compression level. |
Uint8Array — Encoded archive bytes.TypeError— on invalid argument types.ArchiveError— on invalid format, unsafe path, duplicate entry, or limit exceeded.
unpackBytesSync
Section titled “unpackBytesSync”export function unpackBytesSync(
archiveBytes: Uint8Array,
options?: UnpackOptions,
): UnpackedEntry[];
Synchronously unpack an in-memory archive buffer into validated
UnpackedEntry items.
Enforces path-traversal, forbidden-entry, duplicate-entry, size/count, and
compression-bomb (VAEL_ARCHIVE_ZIP_BOMB) protections.
| Name | Type | Description |
|---|---|---|
archiveBytes | Uint8Array | Raw archive container bytes. |
options optional | UnpackOptions | Optional format override and resource limits. |
UnpackedEntry[] — Array of unpacked entries with payload bytes.TypeError— on invalid argument types.ArchiveError— on invalid format, corrupt archive, unsafe path, limit exceeded, or zip bomb.
export function list(path: string, options?: UnpackOptions): Promise<ArchiveEntryInfo[]>;
Asynchronously list validated entry metadata in an archive file on disk without retaining entry payloads.
Available in vjs (vaeljs) only; use listSync in vjs-lite.
| Name | Type | Description |
|---|---|---|
path | string | Path to the archive file on disk. |
options optional | UnpackOptions | Optional format override and resource limits. |
Promise<ArchiveEntryInfo[]> — Promise resolving to an array of ArchiveEntryInfo records.TypeError— on invalid argument types.ArchiveError— on invalid format, corrupt archive, unsafe path, limit exceeded, or I/O error.
listSync
Section titled “listSync”export function listSync(path: string, options?: UnpackOptions): ArchiveEntryInfo[];
Synchronously list validated entry metadata in an archive file on disk without retaining entry payloads.
| Name | Type | Description |
|---|---|---|
path | string | Path to the archive file on disk. |
options optional | UnpackOptions | Optional format override and resource limits. |
ArchiveEntryInfo[] — Array of ArchiveEntryInfo records.TypeError— on invalid argument types.ArchiveError— on invalid format, corrupt archive, unsafe path, limit exceeded, or I/O error.
readEntry
Section titled “readEntry”export function readEntry(
path: string,
entryPath: string,
options?: UnpackOptions,
): Promise<Uint8Array>;
Asynchronously read and verify a single regular file entry from an archive file on disk.
Available in vjs (vaeljs) only; use readEntrySync in vjs-lite.
| Name | Type | Description |
|---|---|---|
path | string | Path to the archive file on disk. |
entryPath | string | Normalized archive-relative path of the regular file entry. |
options optional | UnpackOptions | Optional format override and resource limits. |
Promise<Uint8Array> — Promise resolving to the uncompressed file bytes.TypeError— on invalid argument types.ArchiveError— on missing entry, directory entry, unsafe path, limit exceeded, zip bomb, or I/O error.
readEntrySync
Section titled “readEntrySync”export function readEntrySync(
path: string,
entryPath: string,
options?: UnpackOptions,
): Uint8Array;
Synchronously read and verify a single regular file entry from an archive file on disk.
| Name | Type | Description |
|---|---|---|
path | string | Path to the archive file on disk. |
entryPath | string | Normalized archive-relative path of the regular file entry. |
options optional | UnpackOptions | Optional format override and resource limits. |
Uint8Array — Uncompressed file bytes.TypeError— on invalid argument types.ArchiveError— on missing entry, directory entry, unsafe path, limit exceeded, zip bomb, or I/O error.
extract
Section titled “extract”export function extract(
archivePath: string,
destDir: string,
options?: ExtractOptions,
): Promise<ExtractResult>;
Asynchronously extract an archive file into destDir with symlink guards,
canonical containment checks, and atomic overwrite policy.
Available in vjs (vaeljs) only; use extractSync in vjs-lite.
| Name | Type | Description |
|---|---|---|
archivePath | string | Path to the archive file on disk. |
destDir | string | Destination directory on disk. |
options optional | ExtractOptions | Optional format, overwrite policy, stripComponents, and limits. |
Promise<ExtractResult> — Promise resolving to ExtractResult summary counts.TypeError— on invalid argument types.ArchiveError— on unsafe path, existing target (overwrite: false), limit exceeded, zip bomb, or I/O error.
extractSync
Section titled “extractSync”export function extractSync(
archivePath: string,
destDir: string,
options?: ExtractOptions,
): ExtractResult;
Synchronously extract an archive file into destDir with symlink guards,
canonical containment checks, and atomic overwrite policy.
| Name | Type | Description |
|---|---|---|
archivePath | string | Path to the archive file on disk. |
destDir | string | Destination directory on disk. |
options optional | ExtractOptions | Optional format, overwrite policy, stripComponents, and limits. |
ExtractResult — ExtractResult summary counts.TypeError— on invalid argument types.ArchiveError— on unsafe path, existing target (overwrite: false), limit exceeded, zip bomb, or I/O error.
create
Section titled “create”export function create(
destPath: string,
sources: readonly (string | CreateSource)[],
options?: CreateOptions,
): Promise<CreateResult>;
Asynchronously create an archive file at destPath from host files or
directories without following symlinks, writing via a sibling temp file
and atomic commit.
Available in vjs (vaeljs) only; use createSync in vjs-lite.
| Name | Type | Description |
|---|---|---|
destPath | string | Destination archive file path. |
sources | readonly (string | CreateSource)[] | Host file/directory paths or CreateSource mappings. |
options optional | CreateOptions | Format, optional compression level, and overwrite flag. |
Promise<CreateResult> — Promise resolving to CreateResult summary.TypeError— on invalid argument types.ArchiveError— on existing destination (overwrite: false), unsafe path, or I/O error.
createSync
Section titled “createSync”export function createSync(
destPath: string,
sources: readonly (string | CreateSource)[],
options?: CreateOptions,
): CreateResult;
Synchronously create an archive file at destPath from host files or
directories without following symlinks, writing via a sibling temp file
and atomic commit.
| Name | Type | Description |
|---|---|---|
destPath | string | Destination archive file path. |
sources | readonly (string | CreateSource)[] | Host file/directory paths or CreateSource mappings. |
options optional | CreateOptions | Optional format, compression level, overwrite, symlink, and limit options. |
CreateResult — CreateResult summary.TypeError— on invalid argument types.ArchiveError— on existing destination (overwrite: false), unsafe path, or I/O error.
Classes
Section titled “Classes”ArchiveError
Section titled “ArchiveError”export class ArchiveError extends Error {
override name: "ArchiveError";
code: ArchiveErrorCode;
constructor(code: ArchiveErrorCode, message: string);
}
Error thrown by vael:archive operations carrying a stable
VAEL_ARCHIVE_* error code.
constructor(code: ArchiveErrorCode, message: string);
Construct an ArchiveError.
| Name | Type | Description |
|---|---|---|
code | ArchiveErrorCode | Machine-readable ArchiveErrorCode. |
message | string | Human-readable error message. |
| Property | Type | Description | Since |
|---|---|---|---|
name | "ArchiveError" | Error name ("ArchiveError"). | v0.0.0-alpha.2 |
code | ArchiveErrorCode | Machine-readable VAEL_ARCHIVE_* error classification. | v0.0.0-alpha.2 |
Interfaces
Section titled “Interfaces”ArchiveLimits
Section titled “ArchiveLimits”export interface ArchiveLimits {
maxEntries?: number;
maxFileBytes?: number;
maxTotalBytes?: number;
maxCompressionRatio?: number;
maxPathLen?: number;
maxDepth?: number;
allowDuplicateEntries?: boolean;
}
Security and resource bounds enforced during archive reading, listing, unpacking, and extraction.
| Property | Type | Description | Since |
|---|---|---|---|
maxEntries optional | number | Maximum number of entries permitted in a single archive (default 10_000, hard max 100_000). | v0.0.0-alpha.2 |
maxFileBytes optional | number | Maximum uncompressed bytes for any single entry (default 64 MiB, hard max 1 GiB). | v0.0.0-alpha.2 |
maxTotalBytes optional | number | Maximum total uncompressed bytes across all entries (default 256 MiB, hard max 4 GiB). | v0.0.0-alpha.2 |
maxCompressionRatio optional | number | Maximum allowed decompressed / compressed ratio once output exceeds 1 MiB (default 100). | v0.0.0-alpha.2 |
maxPathLen optional | number | Maximum normalized archive entry path length in bytes (default 1024). | v0.0.0-alpha.2 |
maxDepth optional | number | Maximum path segment depth (default 64). | v0.0.0-alpha.2 |
allowDuplicateEntries optional | boolean | Whether duplicate normalized entry paths are permitted (default false). | v0.0.0-alpha.2 |
PackEntry
Section titled “PackEntry”export interface PackEntry {
path: string;
data?: Uint8Array | string;
isDir?: boolean;
mode?: number;
mtime?: number;
}
Input entry passed to packBytesSync().
| Property | Type | Description | Since |
|---|---|---|---|
path | string | Archive-relative entry path using POSIX / separators. | v0.0.0-alpha.2 |
data optional | Uint8Array | string | File contents as bytes or UTF-8 string (must be empty or omitted when isDir is true). | v0.0.0-alpha.2 |
isDir optional | boolean | Whether this entry is a directory (true) rather than a regular file (false, default). | v0.0.0-alpha.2 |
mode optional | number | Optional Unix permission bits (masked to 0o777 on write). | v0.0.0-alpha.2 |
mtime optional | number | Optional modification time in Unix epoch seconds. | v0.0.0-alpha.2 |
PackOptions
Section titled “PackOptions”export interface PackOptions {
format: ArchiveFormat | "tgz" | "tzst";
level?: number;
}
Options accepted by packBytesSync().
| Property | Type | Description | Since |
|---|---|---|---|
format | ArchiveFormat | "tgz" | "tzst" | Target archive format ("tar", "tar.gz", "tar.zst", or "zip", plus "tgz" / "tzst" aliases). | v0.0.0-alpha.2 |
level optional | number | Optional compression level (0..=9 for gzip/zip, 0..=22 for zstd). | v0.0.0-alpha.2 |
UnpackOptions
Section titled “UnpackOptions”export interface UnpackOptions {
format?: ArchiveFormat | "tgz" | "tzst";
limits?: ArchiveLimits;
}
Options accepted by unpackBytesSync(), list(), listSync(),
readEntry(), and readEntrySync().
| Property | Type | Description | Since |
|---|---|---|---|
format optional | ArchiveFormat | "tgz" | "tzst" | Explicit archive format override; auto-detected from magic bytes or filename extension when omitted. | v0.0.0-alpha.2 |
limits optional | ArchiveLimits | Resource and security bounds applied during reading or unpacking. | v0.0.0-alpha.2 |
UnpackedEntry
Section titled “UnpackedEntry”export interface UnpackedEntry {
readonly path: string;
readonly size: number;
readonly isDir: boolean;
readonly mode: number | null;
readonly mtime: number | null;
readonly data: Uint8Array;
}
Materialized entry returned by unpackBytesSync().
| Property | Type | Description | Since |
|---|---|---|---|
path readonly | string | Validated, normalized archive-relative path. | v0.0.0-alpha.2 |
size readonly | number | Uncompressed entry size in bytes. | v0.0.0-alpha.2 |
isDir readonly | boolean | true when the entry is a directory, false for a regular file. | v0.0.0-alpha.2 |
mode readonly | number | null | Unix mode bits reported by the archive header, or null if absent. | v0.0.0-alpha.2 |
mtime readonly | number | null | Modification time in Unix epoch seconds, or null if absent. | v0.0.0-alpha.2 |
data readonly | Uint8Array | Uncompressed payload bytes (empty for directories). | v0.0.0-alpha.2 |
ArchiveEntryInfo
Section titled “ArchiveEntryInfo”export interface ArchiveEntryInfo {
readonly path: string;
readonly size: number;
readonly compressedSize: number | null;
readonly isDir: boolean;
readonly mode: number | null;
readonly mtime: number | null;
}
Entry metadata summary returned by list() and listSync().
| Property | Type | Description | Since |
|---|---|---|---|
path readonly | string | Validated, normalized archive-relative path. | v0.0.0-alpha.2 |
size readonly | number | Uncompressed entry size in bytes. | v0.0.0-alpha.2 |
compressedSize readonly | number | null | Compressed entry size in bytes (present for ZIP entries, null for TAR). | v0.0.0-alpha.2 |
isDir readonly | boolean | true when the entry is a directory, false for a regular file. | v0.0.0-alpha.2 |
mode readonly | number | null | Unix mode bits reported by the archive header, or null if absent. | v0.0.0-alpha.2 |
mtime readonly | number | null | Modification time in Unix epoch seconds, or null if absent. | v0.0.0-alpha.2 |
ExtractOptions
Section titled “ExtractOptions”export interface ExtractOptions {
format?: ArchiveFormat | "tgz" | "tzst";
overwrite?: boolean;
stripComponents?: number;
allowDuplicateEntries?: boolean;
limits?: ArchiveLimits;
}
Options controlling extract() and extractSync().
| Property | Type | Description | Since |
|---|---|---|---|
format optional | ArchiveFormat | "tgz" | "tzst" | Explicit archive format override; auto-detected from bytes/path when omitted. | v0.0.0-alpha.2 |
overwrite optional | boolean | Whether existing regular files at the destination may be overwritten (default false, which fails with "VAEL_ARCHIVE_ALREADY_EXISTS"). | v0.0.0-alpha.2 |
stripComponents optional | number | Number of leading path components to strip from extracted entry paths (default 0). | v0.0.0-alpha.2 |
allowDuplicateEntries optional | boolean | Whether duplicate normalized entry paths are permitted (default false). | v0.0.0-alpha.2 |
limits optional | ArchiveLimits | Resource and security bounds applied during extraction. | v0.0.0-alpha.2 |
ExtractResult
Section titled “ExtractResult”export interface ExtractResult {
readonly filesExtracted: number;
readonly dirsCreated: number;
readonly totalBytes: number;
}
Summary returned by extract() and extractSync().
| Property | Type | Description | Since |
|---|---|---|---|
filesExtracted readonly | number | Number of regular files written to disk. | v0.0.0-alpha.2 |
dirsCreated readonly | number | Number of directories created or ensured on disk. | v0.0.0-alpha.2 |
totalBytes readonly | number | Total regular file payload bytes written to disk. | v0.0.0-alpha.2 |
CreateSource
Section titled “CreateSource”export interface CreateSource {
path: string;
archivePath?: string;
}
Host file or directory source specification accepted by create() and
createSync().
| Property | Type | Description | Since |
|---|---|---|---|
path | string | Host filesystem path to a regular file or directory. | v0.0.0-alpha.2 |
archivePath optional | string | Optional archive-relative prefix or target path (defaults to path's basename). | v0.0.0-alpha.2 |
CreateOptions
Section titled “CreateOptions”export interface CreateOptions {
format?: ArchiveFormat | "tgz" | "tzst";
level?: number;
overwrite?: boolean;
followSymlinks?: boolean;
limits?: ArchiveLimits;
}
Options controlling create() and createSync().
| Property | Type | Description | Since |
|---|---|---|---|
format optional | ArchiveFormat | "tgz" | "tzst" | Target archive format ("tar", "tar.gz", "tar.zst", or "zip", plus "tgz" / "tzst" aliases). When omitted, inferred from the destPath file extension. | v0.0.0-alpha.2 |
level optional | number | Optional compression level (0..=9 for tar/tar.gz/zip, 0..=22 for tar.zst). | v0.0.0-alpha.2 |
overwrite optional | boolean | Whether an existing file at destPath may be atomically replaced (default false, which fails with "VAEL_ARCHIVE_ALREADY_EXISTS"). | v0.0.0-alpha.2 |
followSymlinks optional | boolean | Whether to follow symbolic links in host source paths (default false, skipping symlinks inside directories and refusing direct symlink sources). | v0.0.0-alpha.2 |
limits optional | ArchiveLimits | Optional entry count, byte size, path length, depth, and duplicate-entry bounds enforced while collecting host sources. | v0.0.0-alpha.2 |
CreateResult
Section titled “CreateResult”export interface CreateResult {
readonly path: string;
readonly entriesWritten: number;
readonly archiveBytes: number;
}
Summary returned by create() and createSync().
| Property | Type | Description | Since |
|---|---|---|---|
path readonly | string | Destination archive path written atomically. | v0.0.0-alpha.2 |
entriesWritten readonly | number | Total archive entries written (files and directories). | v0.0.0-alpha.2 |
archiveBytes readonly | number | Total compressed container bytes written to path. | v0.0.0-alpha.2 |
Type Aliases
Section titled “Type Aliases”ArchiveFormat
Section titled “ArchiveFormat”export type ArchiveFormat = "tar" | "tar.gz" | "tar.zst" | "zip";
Canonical archive container and compression format identifiers.
ArchiveErrorCode
Section titled “ArchiveErrorCode”export type ArchiveErrorCode =
| "VAEL_ARCHIVE_INVALID_FORMAT"
| "VAEL_ARCHIVE_INVALID_ARCHIVE"
| "VAEL_ARCHIVE_UNSAFE_PATH"
| "VAEL_ARCHIVE_UNSUPPORTED_ENTRY_TYPE"
| "VAEL_ARCHIVE_DUPLICATE_ENTRY"
| "VAEL_ARCHIVE_LIMIT_EXCEEDED"
| "VAEL_ARCHIVE_ZIP_BOMB"
| "VAEL_ARCHIVE_ENTRY_NOT_FOUND"
| "VAEL_ARCHIVE_ALREADY_EXISTS"
| "VAEL_ARCHIVE_IO";
Stable machine-readable VAEL_ARCHIVE_* error codes exposed on
ArchiveError.code.
