Skip to content

list ​

list reads the entries of a ZIP, TAR, or TAR.GZ archive without writing anything to disk. The format is identified from the content, never from the file name.

Use it to inspect an untrusted archive before extracting it: entries that unpack would refuse, such as links, are listed with their kind, and names are reported exactly as the archive stores them.

Signaturelist(archive: string, options?: UnpackOptions): Promise<Result<ArchiveEntry[], ArchiveError>>

Minimal example ​

tyrus
import { ArchiveEntry, ArchiveError, list } from "tyrus:archive";

async function inspect(): Promise<Result<void, ArchiveError>> {
    const entries: ArchiveEntry[] = await list("./upload.zip")?;
    print(entries.length); // 3
    print(entries[0].name); // report.pdf
    return Ok();
}

Every option ​

tyrus
import { ArchiveEntry, ArchiveEntryKind, ArchiveError, UnpackOptions, list } from "tyrus:archive";

async function inspect(): Promise<Result<void, ArchiveError>> {
    const entries: ArchiveEntry[] = await list("./upload.zip", {
        maxEntries: 1_000, // reject archives with more entries; default 100000
        timeoutMs: 30_000, // give up after this many milliseconds; default 600000 (10 minutes)
    })?;
    const first: ArchiveEntry = entries[0];
    print(first.name); // report.pdf
    print(first.kind === ArchiveEntryKind.File); // true
    print(first.size); // 20480
    print(first.compressedSize ?? 0); // 18311
    return Ok();
}

list reads only maxEntries and timeoutMs from UnpackOptions; the other options apply to extraction. An archive with more entries fails with ERR_ARCHIVE_ENTRY_LIMIT, and a ZIP archive fails before its entry table is read.