UntarStream
import { UntarStream } from "jsr:@ende/tar";class ยท experimental
class UntarStream implements TransformStream<Uint8Array, TarStreamEntry>Overview
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.
Supported File Formats
Only the ustar file format is supported. This is the most common format. Additionally the numeric extension for file size.
Usage
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.
Understanding Compressed
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.
Example: Usage
import { UntarStream } from "@ende/tar/untar-stream";
import { dirname, normalize } from "@ende/path";
for await (
const entry of (await Ende.open("./out.tar.gz"))
.readable
.pipeThrough(new DecompressionStream("gzip"))
.pipeThrough(new UntarStream())
) {
const path = normalize(entry.path);
await Ende.mkdir(dirname(path), { recursive: true });
await entry.readable?.pipeTo((await Ende.create(path)).writable);
}
Constructors
constructor
new UntarStream()Methods
readable
get readable(): ReadableStream<TarStreamEntry>The ReadableStream
Returns
ReadableStream
Example: Usage
import { UntarStream } from "@ende/tar/untar-stream";
import { dirname, normalize } from "@ende/path";
for await (
const entry of (await Ende.open("./out.tar.gz"))
.readable
.pipeThrough(new DecompressionStream("gzip"))
.pipeThrough(new UntarStream())
) {
const path = normalize(entry.path);
await Ende.mkdir(dirname(path), { recursive: true });
await entry.readable?.pipeTo((await Ende.create(path)).writable);
}
writable
get writable(): WritableStream<Uint8Array>The WritableStream
Returns
WritableStream
Example: Usage
import { UntarStream } from "@ende/tar/untar-stream";
import { dirname, normalize } from "@ende/path";
for await (
const entry of (await Ende.open("./out.tar.gz"))
.readable
.pipeThrough(new DecompressionStream("gzip"))
.pipeThrough(new UntarStream())
) {
const path = normalize(entry.path);
await Ende.mkdir(dirname(path));
await entry.readable?.pipeTo((await Ende.create(path)).writable);
}