/** * TAR Archive - Unified API compatible with ZIP * * Provides TarArchive and TarReader classes with the same interface * as ZipArchive and ZipReader, allowing seamless format switching. */ import { type ArchiveSink } from "../io/archive-sink.js"; import type { ArchiveSource } from "../io/archive-source.js"; import type { ArchiveProgressPhase, ArchiveStreamOptions, ArchiveOperationBase } from "../shared/progress.js"; import { type TarType } from "./tar-constants.js"; import { type TarEntryInfo } from "./tar-entry-info.js"; export interface TarArchiveOptions { /** Default modification time for entries */ modTime?: Date; /** Default abort signal used by streaming operations */ signal?: AbortSignal; /** Default progress callback */ onProgress?: (p: TarArchiveProgress) => void; /** Default throttle for progress callbacks */ progressIntervalMs?: number; } export interface TarArchiveEntryOptions { /** File mode/permissions (default: 0644 for files, 0755 for directories) */ mode?: number; /** User ID (default: 0) */ uid?: number; /** Group ID (default: 0) */ gid?: number; /** User name */ uname?: string; /** Group name */ gname?: string; /** Modification time (default: archive default or now) */ modTime?: Date; /** Alias for modTime - matches TAR field name */ mtime?: Date; /** Entry type (auto-detected from path if not specified) */ type?: TarType; /** Link target (for symlinks) */ linkname?: string; } /** * Progress phase for TAR operations. */ export type TarProgressPhase = ArchiveProgressPhase; /** * Progress information for TAR creation. */ export interface TarArchiveProgress { type: "tar"; phase: TarProgressPhase; entriesTotal: number; entriesDone: number; bytesIn: number; bytesOut: number; currentEntry?: { name: string; index: number; bytesIn: number; }; } /** * Streaming options for TAR creation. */ export type TarArchiveStreamOptions = ArchiveStreamOptions; /** * Operation handle for streaming TAR creation. */ export type TarArchiveOperation = ArchiveOperationBase & { /** Async iterable of TAR output chunks */ iterable: AsyncIterable; }; export interface TarReaderOptions { /** Maximum file size to extract into memory (default: 100MB) */ maxFileSize?: number; /** Default abort signal */ signal?: AbortSignal; /** Default progress callback */ onProgress?: (p: TarReaderProgress) => void; /** Default throttle for progress callbacks */ progressIntervalMs?: number; } export interface TarReaderProgress { type: "untar"; phase: "running" | "done" | "error" | "aborted"; entriesTotal: number; entriesDone: number; bytesIn: number; bytesOut: number; currentEntry?: { path: string; isDirectory: boolean; }; } export interface TarReaderStreamOptions { signal?: AbortSignal; onProgress?: (p: TarReaderProgress) => void; progressIntervalMs?: number; } export interface TarReaderOperation { iterable: AsyncIterable; signal: AbortSignal; abort(reason?: unknown): void; pointer(): number; progress(): TarReaderProgress; } /** * TarArchive - Create TAR archives with ZIP-compatible API * * @example * ```ts * const archive = new TarArchive(); * archive.add("file.txt", "Hello, World!"); * archive.add("dir/", null); // Directory * const bytes = await archive.bytes(); * ``` */ export declare class TarArchive { private readonly _options; private readonly _entries; private _sealed; constructor(options?: TarArchiveOptions); /** * Add an entry to the archive */ add(name: string, source: ArchiveSource | null, options?: TarArchiveEntryOptions): this; /** * Add a directory entry */ addDirectory(name: string, options?: Omit): this; /** * Add a symbolic link */ addSymlink(name: string, target: string, options?: Omit): this; /** * Generate archive as async iterable (matches ZipArchive.stream) */ stream(options?: TarArchiveStreamOptions): AsyncIterable; /** * Get operation object with abort/progress control (matches ZipArchive.operation) */ operation(options?: TarArchiveStreamOptions): TarArchiveOperation; /** * Generate archive as Uint8Array (matches ZipArchive.bytes) */ bytes(options?: TarArchiveStreamOptions): Promise; /** * Generate archive synchronously (matches ZipArchive.bytesSync) */ bytesSync(): Uint8Array; /** * Pipe archive to sink (matches ZipArchive.pipeTo) */ pipeTo(sink: ArchiveSink, options?: TarArchiveStreamOptions): Promise; } export declare class TarReaderEntry { readonly path: string; readonly isDirectory: boolean; readonly info: TarEntryInfo; private readonly _data; constructor(info: TarEntryInfo, data: Uint8Array); /** * Get entry data as Uint8Array (matches UnzipEntry.bytes) */ bytes(): Promise; /** * Get entry data as string (matches UnzipEntry.text) */ text(encoding?: string): Promise; /** * Stream entry data (matches UnzipEntry.stream) */ stream(): AsyncIterable; /** * Pipe entry to sink (matches UnzipEntry.pipeTo) */ pipeTo(sink: ArchiveSink): Promise; /** * Discard entry (matches UnzipEntry.discard) */ discard(): void; } export declare class TarReader { private readonly _source; private readonly _options; private _parsedEntries; constructor(source: ArchiveSource, options?: TarReaderOptions); /** * Iterate over entries (matches ZipReader.entries) */ entries(options?: TarReaderStreamOptions): AsyncIterable; /** * Get operation object with abort/progress control (matches ZipReader.operation) */ operation(options?: TarReaderStreamOptions): TarReaderOperation; /** * Get a specific entry by path (matches ZipReader.get) */ get(path: string): Promise; /** * List all entry paths (matches common pattern) */ list(): Promise; /** * Get bytes of a specific entry (matches ZipReader.bytes) */ bytes(path: string): Promise; /** * Close reader and release resources (matches ZipReader.close) */ close(): Promise; } /** * Create a new TAR archive builder */ export declare function createTarArchive(options?: TarArchiveOptions): TarArchive; /** * Create a new TAR reader */ export declare function createTarReader(source: ArchiveSource, options?: TarReaderOptions): TarReader; export type TarEntryInput = { name: string; source: ArchiveSource; } | [string, ArchiveSource]; /** Helper to add entries to archive from Map or Iterable */ export declare function addEntries(archive: TarArchive, entries: Map | Iterable): void; /** * Create a TAR archive from entries (async) */ export declare function tar(entries: Map | Iterable, options?: TarArchiveOptions): Promise; /** * Create a TAR archive from entries (sync) */ export declare function tarSync(entries: Map | Iterable, options?: TarArchiveOptions): Uint8Array;