@obsidize/tar-browserify
Version:
Browser-based tar utility for packing and unpacking tar files (stream-capable)
67 lines (66 loc) • 3.07 kB
TypeScript
import { TarSerializable } from '../common/tar-utility';
import { UstarHeaderLike } from '../header/ustar/ustar-header-like';
import { ArchiveEntry } from './archive-entry';
export type ArchiveEntryPredicate = (entry: ArchiveEntry) => 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: ArchiveEntry[];
constructor(entries?: ArchiveEntry[]);
/**
* Combines the given array of entries into a single, complete tarball buffer
*/
static serialize(entries: ArchiveEntry[]): 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: ArchiveEntry): this;
/**
* Convenience for appending a new entry to the existing `entries` array.
* @returns `this` for operation chaining
*/
addEntryWith(header: 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: ArchiveEntryPredicate): this;
/**
* Convenience option for cleaning the header of each listed entry.
* When headers are "cleaned", unknown PAX properties will be removed
* (e.g. unwanted MacOS "quarantine" headers), and USTAR fields
* will be normalized (if necessary).
*/
cleanAllHeaders(): this;
}