UNPKG

tar

Version:
159 lines • 6.95 kB
import type { EntryTypeName } from './types.js'; import { type Codec } from './codec.js'; import type { CreateFileHandle, CreateFS, CreateFSSync, CreateStats, FileId } from './fs.js'; import { type PackOptions, type PackOptionsBase, type PackOptionsSync } from './options.js'; import type { ReadEntry, ReadEntrySync } from './read-entry.js'; import { WriteEntry, type EncodeOptions } from './write-entry.js'; /** A directory above a path, when a pack follows symbolic links. */ export type Ancestor = { key: string; up?: Ancestor; }; /** What `Pack` reads for a path before it writes the entry. */ export type PackLoad = { stat: CreateStats; /** The identity of the object: the stat, or exact `dev` and `ino`. */ id: FileId; type: EntryTypeName; /** The target of a symbolic link. */ linkpath?: string; /** The names in a directory. */ names?: string[]; /** A file of `maxReadSize` bytes or less, after 512 bytes of zeros. */ buf?: Uint8Array; /** A larger file. */ handle?: CreateFileHandle; /** The path is a different object now. The pack skips it. */ changed?: boolean; }; /** A path in the queue of a pack. */ export declare class PackJob { path: string; absolute: string; /** The directories above it, when the pack follows symbolic links. */ up?: Ancestor; /** The target, when the pack writes the file as a hard link. */ linkpath?: string; /** Set when `Pack` starts to read the path. */ ready?: Promise<PackLoad | undefined>; constructor(path: string, absolute: string); } /** One item of the queue of a pack, and the item after it. */ export type QueueNode<T> = { item: T; next?: QueueNode<T>; }; /** * The parts of `Pack` and `PackSync` that are the same: the options, * the queue, and the rules that make an entry from a path or from an * entry of another archive. */ export declare abstract class PackBase<FS, E extends ReadEntry | ReadEntrySync, S extends object> { #private; opt: PackOptionsBase<E>; fs?: FS; /** The normalized form of `opt.cwd`. */ cwd?: string; win32: boolean; maxReadSize: number; /** The options of `WriteEntry.encode`. */ header: EncodeOptions; /** The compression of the output. */ codec?: Codec; codecOptions?: Record<string, unknown>; /** True after `end()`. */ ended: boolean; protected head?: QueueNode<PackJob | WriteEntry | E | S>; protected tail?: QueueNode<PackJob | WriteEntry | E | S>; protected wake?: () => void; constructor(opt: PackOptionsBase<E> & { fs?: FS; }, compress: 'compress' | 'compressSync'); /** The absolute form of a path that is relative to `cwd`. */ resolve(path: string): string; /** * Put a path, an entry, or a source of entries at the end of the * queue. A directory is added with all that is in it. */ add(item: string | WriteEntry | E | S): this; /** Add no more. The archive ends after the last item of the queue. */ end(): this; protected push(item: PackJob | WriteEntry | E | S): void; protected shift(): void; /** * True if the pack must read the exact `dev` and `ino` of the * object with the `bigint` option: the numbers are not exact, and a * wrong match loses data. That is a file with more than one link, * which a wrong match makes a hard link to a different file, and * with `follow` a directory, which a wrong match skips as a * directory in itself. Each other object gets no second stat. */ protected needsExact(stat: CreateStats): boolean; /** * The type of the entry to write for a path, or `undefined` to * write no entry. The pack calls it one time for each path, in the * order of the queue. `id` is the stat, or the exact `dev` and `ino` * of the object. */ protected plan(job: PackJob, stat: CreateStats, id: FileId): EntryTypeName | undefined; /** The jobs for the names in the directory of `job`. */ protected children(job: PackJob, names: string[], id: FileId): PackJob[]; /** * Report a path that does not exist, and skip it. Each other error * of the stat is thrown. */ protected missing(job: PackJob, er: unknown): undefined; /** Report a path that is a different object after its `lstat`. */ protected changed(job: PackJob, type: EntryTypeName): void; /** Make the entry for a path. */ protected pathEntry(job: PackJob, stat: CreateStats, type: EntryTypeName, linkpath: string | undefined, body: WriteEntry['body']): WriteEntry; /** * Make the entry to write for an entry that the caller added. * `undefined` if the filter refuses an entry of another archive. */ protected addedEntry(item: WriteEntry | E): WriteEntry | undefined; } /** What `Pack.add()` takes. */ export type PackInput = string | WriteEntry | ReadEntry | AsyncIterable<WriteEntry | ReadEntry> | Iterable<WriteEntry | ReadEntry>; /** What `PackSync.add()` takes. */ export type PackInputSync = string | WriteEntry | ReadEntrySync | Iterable<WriteEntry | ReadEntrySync>; /** * Makes an archive. `add()` paths and entries, then `end()`. The * pack is the async iterator of the bytes of the archive, compressed * if an option selects a codec. * * It reads the file system only when the consumer asks for bytes. * Then it reads the first `jobs` paths of the queue at the same * time, and writes them in the order of the queue. The entries of a * directory go to the end of the queue. * * `return()` closes each file that is open. */ export declare class Pack extends PackBase<CreateFS, ReadEntry, AsyncIterable<WriteEntry | ReadEntry> | Iterable<WriteEntry | ReadEntry>> implements AsyncIterableIterator<Uint8Array, undefined> { #private; jobs: number; constructor(opt?: PackOptions); next(): Promise<IteratorResult<Uint8Array, undefined>>; /** Stop, and close each file that is open. */ return(): Promise<IteratorResult<Uint8Array, undefined>>; [Symbol.asyncIterator](): this; } /** * Makes an archive with no promise. `add()` paths and entries. The * pack is the iterator of the bytes of the archive. It reads the * file system only when the consumer asks for bytes, one path at a * time. The entries of a directory come before the next item that * the caller added. * * The pack ends when the iterator comes to the end of the queue. * With compression, the iterator gives all the archive in one chunk. */ export declare class PackSync extends PackBase<CreateFSSync, ReadEntrySync, Iterable<WriteEntry | ReadEntrySync>> implements IterableIterator<Uint8Array, undefined> { #private; constructor(opt?: PackOptionsSync); next(): IteratorResult<Uint8Array, undefined>; /** Stop, and close the file that is open. */ return(): IteratorResult<Uint8Array, undefined>; [Symbol.iterator](): this; } //# sourceMappingURL=pack.d.ts.map