v0.5.0
Overview
This adds a new StreamSource type for packTar to use. It can accept Readable or ReadableStream types 🗃️
import { packTar, type TarSource } from 'modern-tar/fs';
import { createWriteStream } from 'node:fs';
import { pipeline } from 'node:stream/promises';
// Pack multiple sources
const sources: TarSource[] = [
{ type: 'file', source: './package.json', target: 'project/package.json' },
{ type: 'directory', source: './src', target: 'project/src' },
{ type: 'content', content: 'Hello World!', target: 'project/hello.txt' },
{ type: 'content', content: '#!/bin/bash\necho "Executable"', target: 'bin/script.sh', mode: 0o755 },
{ type: 'stream', content: createReadStream('./large-file.bin'), target: 'project/data.bin', size: 1048576 },
{ type: 'stream', content: fetch('/api/data').then(r => r.body!), target: 'project/remote.json', size: 2048 }
];
const archiveStream = packTar(sources);
await pipeline(archiveStream, createWriteStream('project.tar'));Note this is a breaking change for ContentSource (type: 'content') as we used accept ReadableStream there. This has been moved to StreamSource as it is inherently unsafe to pack tar files from streams with unknown sizes due to OOM or DoS resource exhaustion attacks. tar files must know the size in advance to write the relevant headers and this library should not implicitly buffer such sources.
You must either:
- Acquire the length in advance (such as using
fs.stat/fs.lstator using theContent-Lengthheader). This is already handled for filesystems if you instead pass in thetype: filewith the filepath. - Or buffer it (e.g.
import { buffer } from "node:stream/consumers") yourself.
- feat(pack): accept node readable by @ayuhito in #75
- feat(pack): new stream source for fs packer by @ayuhito in #76
- fix(unpack): handle base 256 bigint numeric headers by @ayuhito in #77
Full Changelog: v0.4.2...v0.5.0