Function assertValidPath

  • Experimental

    Asserts that the path provided is valid for a TarStream.

    UNSTABLE: New API, yet to be vetted.

    It provides a means to check that a path is valid before pipping it through the TarStream, where if invalid will throw an error. Ruining any progress made when archiving.

    Parameters

    • path: string

      The path as a string

    Returns void

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

    const paths = (await Array.fromAsync(Deno.readDir("./")))
    .filter(entry => entry.isFile)
    .map((entry) => entry.name)
    // Filter out any paths that are invalid as they are to be placed inside a Tar.
    .filter(path => {
    try {
    assertValidPath(path);
    return true;
    } catch (error) {
    console.error(error);
    return false;
    }
    });

    await Deno.mkdir('./out/', { recursive: true })
    await ReadableStream.from(paths)
    .pipeThrough(
    new TransformStream<string, TarStreamInput>({
    async transform(path, controller) {
    controller.enqueue({
    type: "file",
    path,
    size: (await Deno.stat(path)).size,
    readable: (await Deno.open(path)).readable,
    });
    },
    }),
    )
    .pipeThrough(new TarStream())
    .pipeThrough(new CompressionStream('gzip'))
    .pipeTo((await Deno.create('./out/archive.tar.gz')).writable);