UNPKG

@ayonli/jsext

Version:

A JavaScript extension package for building strong and modern applications.

50 lines (49 loc) 1.76 kB
import Tarball from "./Tarball.ts"; import { TarOptions } from "./tar.ts"; /** * Options for the {@link untar} function. */ export interface UntarOptions extends TarOptions { /** * The size of the tarball file in bytes. When specified, the progress event * will be dispatched with the `lengthComputable` property set to `true` and * the `total` property set to this value. * * This option is optional when the source is a file path or a file handle, * in which case the size will be determined by the file system. */ size?: number; /** * A callback function that will be called when the extraction progress * changes. */ onProgress?: (event: ProgressEvent) => void; } /** * Extracts files from a tarball file and writes them to the specified directory. * * NOTE: If the destination directory does not exist, it will be created. * * @example * ```ts * import { untar } from "@ayonli/jsext/archive"; * * await untar("/path/to/archive.tar", "/path/to/directory"); * // with gzip * await untar("/path/to/archive.tar.gz", "/path/to/directory", { gzip: true }); * ``` */ export default function untar(src: string | FileSystemFileHandle | ReadableStream<Uint8Array>, dest: string | FileSystemDirectoryHandle, options?: UntarOptions): Promise<void>; /** * Loads the specified tarball file to a {@link Tarball} instance. * * @example * ```ts * import { untar } from "@ayonli/jsext/archive"; * * const tarball = await untar("/path/to/archive.tar"); * // with gzip * const tarball = await untar("/path/to/archive.tar.gz", { gzip: true }); * ``` */ export default function untar(src: string | FileSystemFileHandle | ReadableStream<Uint8Array>, options?: TarOptions): Promise<Tarball>;