node-archiver
node-archiver copied to clipboard
.glob() with options.cwd is not working at 5.x
Just found the source problem, in the pr
https://github.com/archiverjs/node-archiver/pull/433
The non-backward compatibility needs to be documented or clearly communicated to the users !!!
Is there any workaround that can avoid including absolute path?
This was communicated in the changes for 5.0. Its also why it was released as a new major version per semver.
please provide an example of your usage
I ran into the same problem, found the breaking change note in the changelog, and updated my usage:
-archive.glob('../frontend/build/static/js/main.*.js', null, { name: 'ghost-inspector.js', prefix });
+archive.glob('main.*.js', { cwd: '../frontend/build/static/js/'}, { name: 'ghost-inspector.js', prefix });
However the problem I'm having now is that it doesn't seem to be using options.name anymore. The final archive is using the original filenames it found via glob.
EDIT: it appears in the previous version, it only overwrote the entrydata name if options.cwd was set. In version 5.x, it always overwrites the name: https://github.com/archiverjs/node-archiver/pull/433/files#diff-826e5ed9069c92baa50ec46dde8074a6789b4c90837c5ede0e6b0438e3c34309L734-L737
@simpixelated can you provide sn example of file names inside archive and expected names?
@ctalkington
filename inside the archive (matches original filename):
main.7f7102c9.js
expected (with {name: 'ghost-inspector.js'}:
ghost-inspector.js
Here is my use-case. I have files in /a/b/c1/fileN/ and /a/b/c2/filesN for example, and I want to build archive files based on the level of C, keeping the sub-directory structures. So, when user downloaded and unzipped, it shows like c1/filesN and c2/filesN.
@hyoo you should be able to do that with:
archive.directory('a/b/c1', 'c1')
I feel like an idiot but I can't seem to get glob working. I have an array of paths that I want. I'm confused by cwd and to what it refers. I'm using 5.3.0
const output = fs.createWriteStream('output.zip')
const allowedItems = [
'file.xml',
'directory1',
'directory2',
]
archiver.pipe(output)
archiver.directory('/a/directory/path', false)
for (const path of allowedItems) {
archiver.glob(path, { cwd: '????' })
}
archiver.finalize()
Is it the relative path of the real file path or what it will be in the zip? Thanks!
cwd stands for current working directory and tells glob where it should base its search. the glob pattern should be relative to cwd