不包括使用node-tar存档的绝对路径

时间:2019-03-05 16:43:57

标签: javascript node.js tar

我有一个目录,里面包含许多目录和文件,我想将它们添加到tar中。 我使用node-tar软件包。我通过两个参数:path.resolve exec之后的源字符串和目标字符串。最后,我有了tar.gz,其中包括我目标之前的绝对路径。

这就是我所做的:

const path = require('path');
const tar = require('tar');
const { promisify } = require('util');
const tarCreateAsync = promisify(tar.c);

const src = path.resolve(__dirname, 'test-data');
const dst = path.resolve(__dirname, 'output-data');

async function addToTar(src, dst) {
    await tarCreateAsync(
        {
            gzip: true,
            file: path.resolve(dst, 'static.tgz'),
        },
        [src]
    )
}

addToTar(src, dst);

我看过this文章,但API已更改,并且锚点什么也没有显示。

也尝试了preservePaths选项,但没有效果

1 个答案:

答案 0 :(得分:0)

解决它,它是设置基本路径值的Ccwd选项。

看起来像这样

    await tarCreateAsync(
        {
            gzip: true,
            file: path.resolve(dst, 'static.tgz'),
            cwd: path.resolve(__dirname),
        },
        ['test-data']
    )
相关问题