DEFAULT_MAX_BYTESconstconst DEFAULT_MAX_BYTES: numberThe most bytes unxz makes where its caller names no limit.
The xz format read in pure code (commons 0001-formats FR-021 to FR-023): the container of .xz files (one stream or several, each with its blocks, its index and its footer), the LZMA2 filter that every xz file made with the default settings uses, and the checks the container carries (CRC-32, CRC-64 and SHA-256 of what a block holds, the CRC-32 of each header and of the index, and the sizes the headers and the index state). It reads bytes in memory and reaches no file, network or program; its one outside call is the web standard crypto.subtle for SHA-256.
A file that a reader cannot trust is refused whole and nothing is returned: a header or an index that is not what its CRC-32 says, a block whose check differs from its data, an index that does not list the blocks that were read, a filter other than LZMA2, a match that reaches before the start of the data of its block or past its dictionary, a chunk whose compressed size is not the bytes the range decoder consumed, and data that would be larger than maxBytes (a gigabyte unless the caller says another limit) are each damaged or unsupported, and the output never grows past the limit while it is being made, so that a few bytes that expand without end cannot exhaust memory.
import { unxz } from "./xz.ts";
const r = await unxz(bytesOfATarXz);
if (r.kind === "ok") r.value.length; // the length of the tar the file holdsDEFAULT_MAX_BYTESconstconst DEFAULT_MAX_BYTES: numberThe most bytes unxz makes where its caller names no limit.
isXzfunctionfunction isXz(data: Uint8Array<ArrayBufferLike>): booleanWhether bytes begin as an xz file.
unxzfunctionfunction unxz(data: Uint8Array<ArrayBufferLike>, options?: UnxzOptions): Promise<Result<Uint8Array<ArrayBufferLike>, ArchiveError>>The bytes an xz file holds (one stream, or several one after another with zero padding between them), every header, index and check verified. The result is a new array; nothing is returned for a file that fails a check, and the data never grows past options.maxBytes (a gigabyte by default) while it is being made.
UnxzOptionstypeno test imports ittype UnxzOptions = {
/** The most bytes the data may have once it is read; a gigabyte where none is given. */
readonly maxBytes?: number;
};What unxz is given besides the bytes.