assertValidPath
import { assertValidPath } from "jsr:@ende/tar";function ยท experimental
function assertValidPath(path: string): voidAsserts that the path provided is valid for a TarStream.
path: stringThe path as a string
Example: Usage
import { assertValidPath, TarStream, type TarStreamInput } from "@ende/tar";
const paths = (await Array.fromAsync(Ende.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 Ende.mkdir('./out/', { recursive: true })
await ReadableStream.from(paths)
.pipeThrough(
new TransformStream<string, TarStreamInput>({
async transform(path, controller) {
controller.enqueue({
type: "file",
path,
size: (await Ende.stat(path)).size,
readable: (await Ende.open(path)).readable,
});
},
}),
)
.pipeThrough(new TarStream())
.pipeThrough(new CompressionStream('gzip'))
.pipeTo((await Ende.create('./out/archive.tar.gz')).writable);