To create a ZIP file, instantiate a new yazl.ZipFile, add your files or buffers using the provided methods, pipe the outputStream to a writable destination (like a file stream), and finally call .end() to finalize the archive.
Note: When using addFile, you can only add files, not directories. To include a file at a specific path within the ZIP, provide the desired internal path as the second argument.
var yazl = require("yazl");
var fs = require("fs");
var zipfile = new yazl.ZipFile();
// Add a file from the local filesystem
zipfile.addFile("file1.txt", "file1.txt");
// Add a file with a specific internal path
zipfile.addFile("path/to/file.txt", "path/in/zipfile.txt");
// Add a Buffer
zipfile.addBuffer(Buffer.from("hello"), "hello.txt");
// Add a file using a lazy ReadStream (useful for streams like stdin)
zipfile.addReadStreamLazy("stdin.txt", cb => cb(null, process.stdin));
// Pipe the output to a file
zipfile.outputStream.pipe(fs.createWriteStream("output.zip")).on("close", function() {
console.log("done");
});
// Finalize the ZIP file
zipfile.end();