Reputation: 41
I have a dir with a number of dirs and files inside, which I want add to tar.
I use node-tar package for it. I am passing it two params: source and destination strings after path.resolve
exec. Finally I have tar.gz, which includes absolute path before my target.
Here's what I did:
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);
I have seen this article, but the API has been changed and the anchor shows nothing.
Also tried with preservePaths
option but no effect
Upvotes: 2
Views: 1157
Reputation: 41
Solve it, it's been C
or cwd
option for set base path value.
It's look like this
await tarCreateAsync(
{
gzip: true,
file: path.resolve(dst, 'static.tgz'),
cwd: path.resolve(__dirname),
},
['test-data']
)
Upvotes: 2