@obsidize/tar-browserify
Version:
Browser-based tar utility for packing and unpacking tar files (stream-capable)
136 lines (135 loc) • 4.78 kB
TypeScript
import { TarSerializable } from '../../common/tar-utility';
import { PaxTarHeaderKey } from './pax-tar-header-key';
import { PaxTarHeaderSegment } from './pax-tar-header-segment';
/**
* Object of key-value pairs for raw PAX attributes to populate a `PaxTarHeader` instance with.
*/
export interface PaxTarHeaderAttributes extends Record<PaxTarHeaderKey | string, string | number> {
comment: string;
gid: number | string;
gname: string;
hdrcharset: string;
linkpath: string;
mtime: number | string;
path: string;
size: number | string;
uid: number | string;
uname: string;
}
/**
* Adds support for extended headers.
* https://pubs.opengroup.org/onlinepubs/9699919799/utilities/pax.html#tag_20_92_13_03
*/
export declare class PaxTarHeader implements TarSerializable {
private readonly valueMap;
constructor(segments?: PaxTarHeaderSegment[]);
static from(buffer: Uint8Array, offset?: number): PaxTarHeader;
static fromAttributes(attributes: Partial<PaxTarHeaderAttributes>): PaxTarHeader;
static serializeAttributes(attributes: Partial<PaxTarHeaderAttributes>): Uint8Array;
static parseSegmentsFromAttributes(attributes: Partial<PaxTarHeaderAttributes>): PaxTarHeaderSegment[];
static serialize(segments: PaxTarHeaderSegment[]): Uint8Array;
/**
* Wraps the given file name (if necessary) with the 'PaxHeader' metadata indicator.
* If the indicator already exists in the given file name, this does nothing.
*/
static wrapFileName(fileName: string): string;
private static insertPaxAt;
private static makeTopLevelPrefix;
private static parseSegments;
/**
* See `PaxTarHeaderKey.ACCESS_TIME` for more info
*/
get accessTime(): number | undefined;
/**
* See `PaxTarHeaderKey.CHARSET` for more info
*/
get charset(): string | undefined;
/**
* See `PaxTarHeaderKey.COMMENT` for more info
*/
get comment(): string | undefined;
/**
* See `PaxTarHeaderKey.GROUP_ID` for more info
*/
get groupId(): number | undefined;
/**
* See `PaxTarHeaderKey.GROUP_NAME` for more info
*/
get groupName(): string | undefined;
/**
* See `PaxTarHeaderKey.HDR_CHARSET` for more info
*/
get hdrCharset(): string | undefined;
/**
* See `PaxTarHeaderKey.LINK_PATH` for more info
*/
get linkPath(): string | undefined;
/**
* See `PaxTarHeaderKey.MODIFICATION_TIME` for more info
*/
get modificationTime(): number | undefined;
/**
* See `PaxTarHeaderKey.PATH` for more info
*/
get path(): string | undefined;
/**
* See `PaxTarHeaderKey.SIZE` for more info
*/
get size(): number | undefined;
/**
* See `PaxTarHeaderKey.USER_ID` for more info
*/
get userId(): number | undefined;
/**
* See `PaxTarHeaderKey.USER_NAME` for more info
*/
get userName(): string | undefined;
/**
* Converts modificationTime to standard javascript epoch time.
*/
get lastModified(): number | undefined;
/**
* @returns an array of the keys in this header
*/
keys(): string[];
/**
* @returns an array of the segments in this header
*/
values(): PaxTarHeaderSegment[];
/**
* Removes any unknown or un-standardized keys from this header.
* @returns `this` for operation chaining
*/
clean(): this;
/**
* @returns true if the value map of this parsed header contains the given key
*/
has(key: PaxTarHeaderKey | string): boolean;
/**
* @returns the value parsed from the bytes of this header for the given key,
* or `undefined` if the key did not exist in the header.
*/
get(key: PaxTarHeaderKey | string): string | undefined;
/**
* Parse the value for the given key as an int.
* @returns undefined if the key does not exist or the parse operation fails.
*/
getInt(key: PaxTarHeaderKey | string): number | undefined;
/**
* Parse the value for the given key as a float.
* @returns undefined if the key does not exist or the parse operation fails.
*/
getFloat(key: PaxTarHeaderKey | string): number | undefined;
/**
* Serializes the underlying value map of this instance into a set of PAX sectors.
*/
toUint8Array(): Uint8Array;
/**
* Adds any necessary padding to the serialized output to ensure the length
* of the output is a multiple of `SECTOR_SIZE`.
*
* See `toUint8Array()` for more info.
*/
toUint8ArrayPadded(): Uint8Array;
toJSON(): Record<string, unknown>;
}