@obsidize/tar-browserify
Version:
Browser-based tar utility for packing and unpacking tar files (stream-capable)
136 lines (135 loc) • 4.7 kB
TypeScript
import { TarSerializable } from '../../common/tar-utility';
import { PaxHeaderKey } from './pax-header-key';
import { PaxHeaderSegment } from './pax-header-segment';
/**
* Object of key-value pairs for raw PAX attributes to populate a `PaxHeader` instance with.
*/
export interface PaxHeaderAttributes extends Record<PaxHeaderKey | 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 PaxHeader implements TarSerializable {
private readonly valueMap;
constructor(segments?: PaxHeaderSegment[]);
static deserialize(buffer: Uint8Array, offset?: number): PaxHeader;
static fromAttributes(attributes: Partial<PaxHeaderAttributes>): PaxHeader;
static serializeAttributes(attributes: Partial<PaxHeaderAttributes>): Uint8Array;
static parseSegmentsFromAttributes(attributes: Partial<PaxHeaderAttributes>): PaxHeaderSegment[];
static serializeSegments(segments: PaxHeaderSegment[]): 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 deserializeSegments;
/**
* See `PaxHeaderKey.ACCESS_TIME` for more info
*/
get accessTime(): number | undefined;
/**
* See `PaxHeaderKey.CHARSET` for more info
*/
get charset(): string | undefined;
/**
* See `PaxHeaderKey.COMMENT` for more info
*/
get comment(): string | undefined;
/**
* See `PaxHeaderKey.GROUP_ID` for more info
*/
get groupId(): number | undefined;
/**
* See `PaxHeaderKey.GROUP_NAME` for more info
*/
get groupName(): string | undefined;
/**
* See `PaxHeaderKey.HDR_CHARSET` for more info
*/
get hdrCharset(): string | undefined;
/**
* See `PaxHeaderKey.LINK_PATH` for more info
*/
get linkPath(): string | undefined;
/**
* See `PaxHeaderKey.MODIFICATION_TIME` for more info
*/
get modificationTime(): number | undefined;
/**
* See `PaxHeaderKey.PATH` for more info
*/
get path(): string | undefined;
/**
* See `PaxHeaderKey.SIZE` for more info
*/
get size(): number | undefined;
/**
* See `PaxHeaderKey.USER_ID` for more info
*/
get userId(): number | undefined;
/**
* See `PaxHeaderKey.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(): PaxHeaderSegment[];
/**
* 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: PaxHeaderKey | 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: PaxHeaderKey | 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: PaxHeaderKey | 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: PaxHeaderKey | 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>;
}