UNPKG

@obsidize/tar-browserify

Version:

Browser-based tar utility for packing and unpacking tar files (stream-capable)

66 lines (65 loc) 2.98 kB
import { TarSerializable } from '../common/tar-utility'; import { TarEntry } from '../entry/tar-entry'; import { UstarHeaderLike } from '../header/ustar/ustar-header-like'; export type TarEntryPredicate = (entry: TarEntry) => boolean; /** * Generic utility for building a tar octet stream by adding JSON-style entries. * See the `add***()` options in this class definition for details. */ export declare class ArchiveWriter implements TarSerializable { entries: TarEntry[]; constructor(entries?: TarEntry[]); /** * Combines the given array of entries into a single, complete tarball buffer */ static serialize(entries: TarEntry[]): Uint8Array; /** * @returns a complete tar buffer from all the currently set tar entries in this instance. */ toUint8Array(): Uint8Array; /** * Convenience for appending a new entry to the existing `entries` array * @returns `this` for operation chaining */ addEntry(entry: TarEntry): this; /** * Convenience for appending a new entry to the existing `entries` array. * Uses `TarEntry.from()` on the given parameters to create the entry. * @returns `this` for operation chaining */ addEntryWith(header: UstarHeaderLike | Partial<UstarHeaderLike>, content?: Uint8Array): this; /** * Convenience option for building tarball data * @param path - the file name, e.g. './relative/path/to/your/file.txt' * @param content - the content of the file (shocker!) * @param headerOptions - custom options for this entry * @returns `this` for operation chaining */ addTextFile(path: string, content: string, headerOptions?: Partial<UstarHeaderLike>): this; /** * Convenience option for building tarball data * @param path - the file name, e.g. './relative/path/to/your/file.bin' * @param content - the content of the file (shocker!) * @param headerOptions - custom options for this entry * @returns `this` for operation chaining */ addBinaryFile(path: string, content: Uint8Array, headerOptions?: Partial<UstarHeaderLike>): this; /** * Convenience option for building tarball data * @param path - the directory name, e.g. './relative/path/to/your/dir' * @param headerOptions - custom options for this entry * @returns `this` for operation chaining */ addDirectory(path: string, headerOptions?: Partial<UstarHeaderLike>): this; /** * Removes any entries from this writer's cache that meet the given predicate condition. * @param predicate - delegate that will return true for any entry that should be removed. * @returns `this` for operation chaining */ removeEntriesWhere(predicate: TarEntryPredicate): this; /** * Convenience option for cleaning the header of each listed entry. * See also `TarHeader.clean()`. */ cleanAllHeaders(): this; }