tar
Version:
tar for JavaScript
155 lines • 5.97 kB
TypeScript
import { SymlinkError } from './symlink-error.js';
import type { ExtractStats } from './fs.js';
import { type MkdirOptions } from './mkdir.js';
import { type ExtractOptions, type ExtractOptionsSync, type ReadOptions, type TarInput, type TarInputSync, type UnpackOptions } from './options.js';
import type { EntryData, ReadEntry, ReadEntrySync } from './read-entry.js';
import { type WarnData } from './warn.js';
import { type OpenConstants } from './write-flag.js';
/** The options that `UnpackBase` reads. */
export type UnpackBaseOptions<E extends EntryData> = ReadOptions<E> & UnpackOptions & {
fs: {
constants?: OpenConstants;
};
};
/**
* The parts of the extraction that do not use the file system: the
* options, the checks of each entry, and the warnings. `Unpack` and
* `UnpackSync` add the file system work.
*/
export declare class UnpackBase<E extends EntryData, O extends UnpackBaseOptions<E> = UnpackBaseOptions<E>> {
#private;
/** The options, with no prototype. */
opt: O;
/** The absolute path of the extraction directory. */
cwd: string;
win32: boolean;
strip: number;
maxDepth: number;
preservePaths: boolean;
unlink: boolean;
keep: boolean;
newer: boolean;
noMtime: boolean;
chmod: boolean;
uid?: number;
gid?: number;
preserveOwner: boolean;
forceChown: boolean;
processUid?: number;
processGid?: number;
processUmask: number;
umask: number;
dmode: number;
fmode: number;
/** Gives the `open` flag for a new file of a given size. */
writeFlag: (size: number) => string | number;
/** Resolve a path from an absolute path. */
resolve: (base: string, path: string) => string;
/** The parent directory of an absolute path. */
dirname: (path: string) => string;
/** Set when an error stops the extraction. */
fatal?: {
error: unknown;
};
constructor(options: O);
/**
* Report a problem to `onwarn`, or throw it if `strict` is set. A
* damaged archive is always an error here, because the extraction
* cannot be complete.
*/
warn(code: string, message: string | Error, data?: WarnData): void;
/** The options for the reader. Its warnings go to `warn()`. */
readerOptions(): ReadOptions<E>;
/**
* Report the failure of one entry as a `TAR_ENTRY_ERROR` warning.
* Throws the error if it stops the extraction: the extraction
* directory is not usable, the archive cannot be read, or `strict`
* is set.
*/
entryError(er: unknown, entry: E): void;
/** Record the error that stops the extraction. Returns it. */
fail(error: unknown): unknown;
/**
* Check the entry, with no use of the file system. Set its
* `absolute` path, and change its `path`, `linkpath`, and `mode` to
* the values to extract. False if the entry must not be extracted.
*/
check(entry: E): boolean;
/**
* The paths that the entry must have for itself while it is made.
* A link also reserves its target, so that an entry that makes the
* target, and an entry that goes through the link, do not run at
* the same time as the link.
*/
reservedPaths(entry: E): string[];
/** The options to make a directory with a mode. */
mkdirOptions(mode: number): MkdirOptions;
/**
* The owner to set on the entry, if it needs one: with
* `preserveOwner`, when the owner in the archive is not the process
* owner, and with `uid` and `gid`, when they are not the process
* owner.
*/
owner(entry: E): {
uid: number;
gid: number;
} | undefined;
/** The times to set on the entry, if it needs them. */
times(entry: E): {
atime: Date;
mtime: Date;
} | undefined;
/** True if the object on disk at the path of the entry must stay. */
skip(entry: E, st: ExtractStats): boolean;
/**
* True if the entry can be written into the file that is on disk.
* A file with more than one link is not used, because the write
* would change the other links. Windows does not report a useful
* link count.
*/
isReusable(entry: E, st: ExtractStats): boolean;
/**
* The parts of the path from the extraction directory to the
* target of a link entry. None of them can be a symbolic link.
*/
linkParts(entry: E, absolute: string): string[];
/**
* The parts of the path from the extraction directory to the
* parent directory of an entry. The extraction checks them again
* after it makes the entry: none of them can be a symbolic link
* then. So a directory that another process replaced with a
* symbolic link during the extraction is an error of the entry.
*/
parentParts(absolute: string): string[];
/** The error for a link target that goes through a symbolic link. */
symlinkError(symlink: string, parts: string[]): SymlinkError;
}
/**
* Extracts the entries of an archive with async file system
* functions.
*
* Several entries are extracted at one time. Entries that use the
* same path, or a path and a directory above it, are extracted in
* the order of the archive.
*/
export declare class Unpack extends UnpackBase<ReadEntry, ExtractOptions> {
#private;
constructor(opt: ExtractOptions);
/**
* Extract the archive. The promise settles when all the file
* system work is done. It rejects with the first error that stops
* the extraction.
*/
extract(input: TarInput): Promise<void>;
}
/**
* Extracts the entries of an archive with sync file system
* functions, one entry at a time.
*/
export declare class UnpackSync extends UnpackBase<ReadEntrySync, ExtractOptionsSync> {
#private;
constructor(opt: ExtractOptionsSync);
/** Extract the archive. Throws the first error that stops it. */
extract(input: TarInputSync): void;
}
//# sourceMappingURL=unpack.d.ts.map