/** * Tar container — create and read POSIX `ustar` archives. * * Pure TypeScript, no engine: tar is a framing format, not a codec. {@link tar} * concatenates 512-byte headers and padded payloads; {@link untar} walks them * back. Long paths and large (>8 GB) entries transparently use PAX extended * headers, and reading understands the GNU long-name (`L`) and PAX (`x`/`g`) * records that `tar`/Docker emit — so archives round-trip with the standard * Unix `tar` CLI and Docker image layers. * * Combine with a codec for the usual on-disk forms: {@link tarGz} (`.tar.gz`) * and {@link tarZstd} (`.tar.zst`) pipe the framing through gzip/zstd so callers * never hand-wire two functions. * * @example * ```ts * import { tar, untar, tarGz } from '@myrialabs/zipkit'; * const archive = tar([ * { name: 'hello.txt', data: strToU8('hi') }, * { name: 'src/', type: 'directory' } * ]); * const gz = await tarGz([{ name: 'big.log', data: bytes }]); * const files = untar(archive); * ``` */ import type { CompressOptions, DecompressOptions } from '../types.js'; /** Entry kind, normalized across the on-disk typeflags. */ export type TarEntryType = 'file' | 'directory' | 'symlink'; /** An entry to write into a tar archive. */ export interface TarEntryInput { /** Path within the archive, using `/` separators. */ name: string; /** File contents. Omit (or leave empty) for directories and symlinks. */ data?: Uint8Array; /** Entry kind (default `'file'`, or `'directory'` when `name` ends in `/`). */ type?: TarEntryType; /** Unix permission bits, e.g. `0o644`. Defaults by type. */ mode?: number; /** Last-modified time (default: now). */ mtime?: Date | number; /** Owner uid (default `0`). */ uid?: number; /** Owner gid (default `0`). */ gid?: number; /** Owner user name. */ uname?: string; /** Owner group name. */ gname?: string; /** Symlink target (required when `type` is `'symlink'`). */ linkname?: string; } /** A decoded tar entry. */ export interface TarEntry { /** Path within the archive. */ name: string; /** File contents (empty for directories/symlinks). */ data: Uint8Array; /** Entry kind. */ type: TarEntryType; /** Unix permission bits. */ mode: number; /** Last-modified time. */ mtime: Date; /** Owner uid. */ uid: number; /** Owner gid. */ gid: number; /** Owner user name, if recorded. */ uname: string; /** Owner group name, if recorded. */ gname: string; /** Symlink target, if this is a symlink. */ linkname?: string; /** Uncompressed size in bytes. */ size: number; } /** * Create a tar archive from `entries`. Synchronous and engine-free. Emits PAX * extended headers for paths over 100 bytes that don't fit the ustar * prefix/name split, and for entries larger than 8 GB (ustar's octal size * ceiling). The result ends with the two zero blocks `tar` expects. */ export declare function tar(entries: TarEntryInput[]): Uint8Array; /** * Read a tar archive into its entries. Synchronous and engine-free. Understands * the ustar prefix/name split, GNU long-name/long-link records, and PAX * extended headers (so it reads archives from the Unix `tar` CLI and Docker * layers). Throws {@link ZipKitError} on a corrupt header checksum. */ export declare function untar(data: Uint8Array): TarEntry[]; /** Create a `.tar.gz` archive: {@link tar} then gzip. */ export declare function tarGz(entries: TarEntryInput[], opts?: CompressOptions): Promise; /** Read a `.tar.gz` archive: gunzip then {@link untar}. */ export declare function untarGz(data: Uint8Array, opts?: DecompressOptions): Promise; /** Create a `.tar.zst` archive: {@link tar} then zstd. */ export declare function tarZstd(entries: TarEntryInput[], opts?: CompressOptions): Promise; /** Read a `.tar.zst` archive: unzstd then {@link untar}. */ export declare function untarZstd(data: Uint8Array, opts?: DecompressOptions): Promise; //# sourceMappingURL=index.d.ts.map