Function assertValidTarStreamOptions

  • Experimental

    Asserts that the options provided are valid for a TarStream.

    UNSTABLE: New API, yet to be vetted.

    Parameters

    Returns void

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

    const paths = (await Array.fromAsync(Deno.readDir('./')))
    .filter(entry => entry.isFile)
    .map(entry => entry.name);

    await Deno.mkdir('./out/', { recursive: true })
    await ReadableStream.from(paths)
    .pipeThrough(new TransformStream<string, TarStreamInput>({
    async transform(path, controller) {
    const stats = await Deno.stat(path);
    const options = { mtime: stats.mtime?.getTime()! / 1000 };
    try {
    // Filter out any paths that would have an invalid options provided.
    assertValidTarStreamOptions(options);
    controller.enqueue({
    type: "file",
    path,
    size: stats.size,
    readable: (await Deno.open(path)).readable,
    options,
    });
    } catch (error) {
    console.error(error);
    }
    },
    }))
    .pipeThrough(new TarStream())
    .pipeThrough(new CompressionStream('gzip'))
    .pipeTo((await Deno.create('./out/archive.tar.gz')).writable);