【发布时间】:2021-10-02 01:22:16
【问题描述】:
基本上我想做与How to strip path while archiving with TAR 等效的操作,但将 tar 命令导入 NodeJS,所以目前我正在这样做:
const gzip = zlib.createGzip();
const pack = new tar.Pack(prefix="");
const source = Readable.from('public/images/');
const destination = fs.createWriteStream('public/archive.tar.gz');
pipeline(source, pack, gzip, destination, (err) => {
if (err) {
console.error('An error occurred:', err);
process.exitCode = 1;
}
});
但是这样做会给我留下像“/public/images/a.png”和“public/images/b.png”这样的文件,而我想要的是像“/a.png”和“/b”这样的文件.png”。我想知道如何添加到此过程中以去除不需要的目录,同时将文件保留在原处。
【问题讨论】: