@obsidize/tar-browserify
Version:
Browser-based tar utility for packing and unpacking tar files (stream-capable)
91 lines (90 loc) • 4.38 kB
TypeScript
import { UstarHeaderFieldTransform } from './ustar-header-field-transform';
import { UstarHeaderFieldType } from './ustar-header-field-type';
import { UstarHeaderLike } from './ustar-header-like';
/**
* Metadata about a single field for a tar header.
* These are used to dynamically parse fields as a header sector is stepped through.
*
* See extractTarEntry() and TarUtility for more info.
*/
export interface UstarHeaderFieldLike {
readonly name: keyof UstarHeaderLike;
readonly offset: number;
readonly size: number;
readonly type: UstarHeaderFieldType;
constantValue?: any;
}
/**
* Definitions taken from here:
* https://en.wikipedia.org/wiki/Tar_(computing)
*/
export declare class UstarHeaderField<T> implements UstarHeaderFieldLike {
readonly name: keyof UstarHeaderLike;
readonly offset: number;
readonly size: number;
readonly type: UstarHeaderFieldType;
readonly constantValue: any;
readonly transform: UstarHeaderFieldTransform<T>;
constructor(config: UstarHeaderFieldLike);
static frozen<T>(config: UstarHeaderFieldLike): UstarHeaderField<T>;
static readonly fileName: UstarHeaderField<string>;
static readonly fileMode: UstarHeaderField<number>;
static readonly ownerUserId: UstarHeaderField<number>;
static readonly groupUserId: UstarHeaderField<number>;
static readonly fileSize: UstarHeaderField<number>;
static readonly lastModified: UstarHeaderField<number>;
static readonly headerChecksum: UstarHeaderField<number>;
static readonly typeFlag: UstarHeaderField<string>;
static readonly linkedFileName: UstarHeaderField<string>;
static readonly ustarIndicator: UstarHeaderField<string>;
static readonly ustarVersion: UstarHeaderField<string>;
static readonly ownerUserName: UstarHeaderField<string>;
static readonly ownerGroupName: UstarHeaderField<string>;
static readonly deviceMajorNumber: UstarHeaderField<string>;
static readonly deviceMinorNumber: UstarHeaderField<string>;
static readonly fileNamePrefix: UstarHeaderField<string>;
static all(): UstarHeaderField<any>[];
static checksumSet(): UstarHeaderField<any>[];
/**
* Shorthand for padding the output of `slice` into `decodeString`.
*/
sliceString(input: Uint8Array, offset?: number): string;
/**
* @param input - a buffer of one or more complete tar sectors
* @param offset - the offset to slice from (must be a multiple of `SECTOR_SIZE`)
* @returns the slice of the given input Uint8Array that this field resides in.
*/
slice(input: Uint8Array, offset?: number): Uint8Array;
/**
* @param input - a buffer of one or more complete tar sectors
* @returns The value parsed from the input based on this field's transform type,
* or `undefined` on error.
*/
deserialize(input: Uint8Array, offset?: number): T | undefined;
/**
* @param input - the value to be serialized, based on this field's transform type.
* @returns the serialized value as a Uint8Array
*/
serialize(input: T): Uint8Array;
/**
* Runs `deserialize()` while also taking this field's offset into account.
*/
readFrom(input: Uint8Array, offset: number): T | undefined;
/**
* Serialize the given value and set the output bytes in the given output buffer.
* @param output - the output buffer to be written to
* @param headerOffset - the offset of the header in the output buffer to insert the update.
* Note that this field's offset will be added to the header offset when inserting.
* @param value - the value to be serialized
* @returns true if the buffer was updated
*/
writeTo(output: Uint8Array, headerOffset: number, value: T): boolean;
/**
* Calculates the checksum value for this field in the given input buffer, at the given offset.
* All field checksum values are aggregated together to form the main header checksum entry.
* @param input - the input buffer to extract a field checksum from
* @param offset - the offset of the header in the buffer (will be combined with this field's offset)
* @returns the checksum value for this specific field
*/
calculateChecksum(input: Uint8Array, offset?: number): number;
}