Class UntarStreamExperimental

A TransformStream to expand a tar archive. Tar archives allow for storing multiple files in a single file (called an archive, or sometimes a tarball).

These archives typically have a single '.tar' extension. This implementation follows the FreeBSD 15.0 spec.

Only the ustar file format is supported. This is the most common format. Additionally the numeric extension for file size.

When expanding the archive, as demonstrated in the example, one must decide to either consume the ReadableStream property, if present, or cancel it. The next entry won't be resolved until the previous ReadableStream is either consumed or cancelled.

A tar archive may be compressed, often identified by an additional file extension, such as '.tar.gz' for gzip. This TransformStream does not support decompression which must be done before expanding the archive.

UNSTABLE: New API, yet to be vetted.

import { UntarStream } from "@std/tar/untar-stream";
import { dirname, normalize } from "@std/path";

for await (
const entry of (await Deno.open("./out.tar.gz"))
.readable
.pipeThrough(new DecompressionStream("gzip"))
.pipeThrough(new UntarStream())
) {
const path = normalize(entry.path);
await Deno.mkdir(dirname(path), { recursive: true });
await entry.readable?.pipeTo((await Deno.create(path)).writable);
}
Implements

Constructors

Accessors

Constructors

Accessors

  • get readable(): ReadableStream<TarStreamEntry>
  • Experimental

    The ReadableStream

    Returns ReadableStream<TarStreamEntry>

    ReadableStream

    import { UntarStream } from "@std/tar/untar-stream";
    import { dirname, normalize } from "@std/path";

    for await (
    const entry of (await Deno.open("./out.tar.gz"))
    .readable
    .pipeThrough(new DecompressionStream("gzip"))
    .pipeThrough(new UntarStream())
    ) {
    const path = normalize(entry.path);
    await Deno.mkdir(dirname(path), { recursive: true });
    await entry.readable?.pipeTo((await Deno.create(path)).writable);
    }
  • get writable(): WritableStream<Uint8Array>
  • Experimental

    The WritableStream

    Returns WritableStream<Uint8Array>

    WritableStream

    import { UntarStream } from "@std/tar/untar-stream";
    import { dirname, normalize } from "@std/path";

    for await (
    const entry of (await Deno.open("./out.tar.gz"))
    .readable
    .pipeThrough(new DecompressionStream("gzip"))
    .pipeThrough(new UntarStream())
    ) {
    const path = normalize(entry.path);
    await Deno.mkdir(dirname(path));
    await entry.readable?.pipeTo((await Deno.create(path)).writable);
    }