node-archiver
node-archiver copied to clipboard
Add an option to allow following the symlinks
This change will expose an option when creating an Archiver object to allow following the symlinks, so instead of archiving the symlinks, the target folders and files of the symlinks will be archived.
The usage will be something like:
const archive = new ZipArchive( {
followSymLinks: true,
zlib: { level: 9 },
} );
Proposed changes
- Add an
optionto theCoreOptionsobject namedfollowSymlinks - Use that option to populate the
followoption of thereaddirGlobfunction, so the symlinks are followed.
Testing instructions
- Clone this repository and apply this branch
- Create a new Javascript repository and install this repo, for example:
- Create a new folder in the same root folder where the
node-archiverrepo was cloned, e.g. /test-archiver` cdinto that folder- Run
npm init -y - Run
npm i ../node-archiver - Create another folder in another location that you will use for testing to compress the files, e.g.
/tmp/test-folder - Include some symbolic links in that folder that point to directories and to individual files
- So you should have a similar structure than the following:
- Create a new folder in the same root folder where the
- cd into the
test-archiverfolder - Create the following code to test the new option in a file named
index.js:
import { ZipArchive } from "archiver";
import fs from "fs";
const archive = new ZipArchive({
followSymLinks: true,
zlib: { level: 9 },
});
const output = fs.createWriteStream("example.zip");
archive.on("warning", function (err) {
if (err.code === "ENOENT") {
// log warning
console.log(err);
} else {
// throw error
throw err;
}
});
output.on("close", function () {
console.log(archive.pointer() + " total bytes");
console.log("archiver has been finalized and the output file descriptor has closed.");
});
archive.on("error", function (err) {
throw err;
});
archive.pipe(output);
archive.directory("../test-folder", "example");
archive.finalize().catch(console.error).then(() => console.log('Done'));
- Run the above code with
node index.js - Check there are not unexpected errors
- Check that a new
example.zipfile has been created in that folder - unzip the file and confirm the symlinks created have been followed, so you should see standard folders and files
@ctalkington, do you think we could consider exposing this follow symlinks readdir-glob option?