@obsidize/tar-browserify
Version:
Browser-based tar utility for packing and unpacking tar files (stream-capable)
109 lines (108 loc) • 4.52 kB
TypeScript
import { ArchiveContext } from '../common/archive-context';
import { AsyncUint8ArrayLike } from '../common/async-uint8-array';
import { TarSerializable } from '../common/tar-utility';
import { TarHeader } from '../header/tar-header';
import { UstarHeaderLike } from '../header/ustar/ustar-header-like';
import { UstarHeaderLinkIndicatorType } from '../header/ustar/ustar-header-link-indicator-type';
export interface ArchiveEntryOptions {
header?: TarHeader;
headerAttributes?: Partial<UstarHeaderLike>;
headerByteLength?: number;
content?: Uint8Array | null;
offset?: number;
context?: ArchiveContext | null;
}
/**
* Container for metadata and content of a tarball entry.
*
* Here, we consider an "entry" to be a tuple of:
* 1. The parsed USTAR header sector content (AKA TarHeader)
* 2. The aggregate of the proceeding file content sectors, based on the header's file size attribute
*/
export declare class ArchiveEntry implements UstarHeaderLike, TarSerializable {
private mHeader;
private mHeaderByteLength;
private mContent;
private mOffset;
private mContext;
constructor(options?: ArchiveEntryOptions);
static isArchiveEntry(v: any): boolean;
get fileName(): string;
get fileSize(): number;
get fileMode(): number;
get ownerUserId(): number;
get groupUserId(): number;
get lastModified(): number;
get headerChecksum(): number;
get linkedFileName(): string;
get typeFlag(): UstarHeaderLinkIndicatorType;
get ustarIndicator(): string;
get ustarVersion(): string;
get ownerUserName(): string;
get ownerGroupName(): string;
get deviceMajorNumber(): string;
get deviceMinorNumber(): string;
get fileNamePrefix(): string;
/**
* The header metadata parsed out for this entry.
* If you are attempting to read the content of this entry,
* do not modify this instance.
*/
get header(): TarHeader;
/**
* The file content for this entry.
* This may be null for entries loaded asynchronously, or
* for non-file entries like directories.
*/
get content(): Uint8Array | null | undefined;
/**
* The starting absolute index (inclusive) in the source buffer that this entry was parsed from.
* Returns zero by default if this was not parsed by a source buffer.
*/
get sourceOffset(): number;
/**
* The size in bytes of the header in the source buffer that this entry was parsed from.
* Returns zero by default if this was not parsed by a source buffer.
*/
get sourceHeaderByteLength(): number;
/**
* The context (if any) from which this entry was parsed.
* The context will include global data about things such as
* the origin of the archive and global pax headers.
*/
get sourceContext(): ArchiveContext | null | undefined;
isDirectory(): boolean;
isFile(): boolean;
/**
* Convenience for decoding the current content buffer as a string.
* Note that if the content was not loaded for whatever reason, this
* will return an empty string.
* @returns The decoded string data from the currently assigned content,
* or an empty string if there is no content assigned.
*/
text(): string;
/**
* Only necessary if this entry was extracted from an async buffer, since the entry
* does not hold the content of async buffers by default.
*
* If the entry was extracted synchronously, its content will be available via the "content" property.
*
* Do not use this on entries that have not been parsed from a source buffer,
* otherwise it will very likely return garbage data.
*
* @param buffer - the source to read content from
* @param offset - the _relative_ offset of the content to read;
* setting this to 42 will start reading at the 42nd byte index within the content block
* @param length - the number of bytes to read after the offset
*/
readContentFrom(buffer: AsyncUint8ArrayLike, offset?: number, length?: number): Promise<Uint8Array>;
/**
* @returns This instance serialized as a single slice for a tar buffer
*/
toUint8Array(): Uint8Array;
/**
* Overridden to prevent circular reference errors / huge memory spikes that would
* include the underlying content by default.
*/
toJSON(): Record<string, unknown>;
}