IF Commons GitHub

xz

Written to: 2 requirements: 2 proved, 0 partly, 0 failing, 0 with no test recorded. 0001-formats FR-021, 0001-formats FR-022

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 holds

Source: commons/formats/src/xz.ts

3 of 4 exports are imported by a test of the run. A test that imports an export may not call it or check what it returns.

DEFAULT_MAX_BYTESconst
const DEFAULT_MAX_BYTES: number

The most bytes unxz makes where its caller names no limit.

Imported by 5 tests of the run (5 passed, 0 failed): the library's results

isXzfunction
function isXz(data: Uint8Array<ArrayBufferLike>): boolean

Whether bytes begin as an xz file.

Imported by 5 tests of the run (5 passed, 0 failed): the library's results

unxzfunction
function 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.

Imported by 5 tests of the run (5 passed, 0 failed): the library's results

UnxzOptionstypeno test imports it
type 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.

Titles, headings, exports, tables, columns and requirements. Esc closes.