Class TarStreamExperimental

A TransformStream to create 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.

The ustar file format is used for creating the tar archive. While this format is compatible with most tar readers, the format has several limitations, including:

  • Paths must be at most 256 characters.
  • Files must be at most 8 GiBs in size, or 64 GiBs if sizeExtension is set to true.
  • Sparse files are not supported.

TarStream may throw an error for several reasons. A few of those are:

  • The path is invalid.
  • The size provided does not match that of the iterable's length.

Tar archives are not compressed by default. If you'd like to compress the archive, you may do so by piping it through a compression stream.

UNSTABLE: New API, yet to be vetted.

import { TarStream, type TarStreamInput } from "@std/tar/tar-stream";

await ReadableStream.from<TarStreamInput>([
{
type: "directory",
path: 'potato/'
},
{
type: "file",
path: 'deno.json',
size: (await Deno.stat('deno.json')).size,
readable: (await Deno.open('deno.json')).readable
},
{
type: "file",
path: '.vscode/settings.json',
size: (await Deno.stat('.vscode/settings.json')).size,
readable: (await Deno.open('.vscode/settings.json')).readable
}
])
.pipeThrough(new TarStream())
.pipeThrough(new CompressionStream('gzip'))
.pipeTo((await Deno.create('./out.tar.gz')).writable)
Implements

Constructors

Accessors

Constructors

Accessors

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

    The ReadableStream

    Returns ReadableStream<Uint8Array>

    ReadableStream

    import { TarStream } from "@std/tar/tar-stream";

    await ReadableStream.from([
    {
    type: "directory",
    path: 'potato/'
    },
    {
    type: "file",
    path: 'deno.json',
    size: (await Deno.stat('deno.json')).size,
    readable: (await Deno.open('deno.json')).readable
    },
    {
    type: "file",
    path: '.vscode/settings.json',
    size: (await Deno.stat('.vscode/settings.json')).size,
    readable: (await Deno.open('.vscode/settings.json')).readable
    }
    ])
    .pipeThrough(new TarStream())
    .pipeThrough(new CompressionStream('gzip'))
    .pipeTo((await Deno.create('./out.tar.gz')).writable)
  • get writable(): WritableStream<TarStreamInput>
  • Experimental

    The WritableStream

    Returns WritableStream<TarStreamInput>

    WritableStream

    import { TarStream } from "@std/tar/tar-stream";

    await ReadableStream.from([
    {
    type: "directory",
    path: 'potato/'
    },
    {
    type: "file",
    path: 'deno.json',
    size: (await Deno.stat('deno.json')).size,
    readable: (await Deno.open('deno.json')).readable
    },
    {
    type: "file",
    path: '.vscode/settings.json',
    size: (await Deno.stat('.vscode/settings.json')).size,
    readable: (await Deno.open('.vscode/settings.json')).readable
    }
    ])
    .pipeThrough(new TarStream())
    .pipeThrough(new CompressionStream('gzip'))
    .pipeTo((await Deno.create('./out.tar.gz')).writable)