1.0.1 • Published 6 years ago
@jyd119/mzip v1.0.1
node-zip
node-zip is a node addon binding Minizip for reading/writing zip files.
Quick Start
Reading zip file
const r = await zip.open('./tests/test.zip');
r.exists('yargs/index.js'); // true
// List files in the zip
for (let i = 0; i < r.count; ++i) {
// console.log(r.item(i));
}
// Extract all files
await r.extract_all('./tests/temp/all');
// Extract files matching the specified pattern
await r.extract_all('./tests/temp/partial', 'yargs/locales/**');
r.close();Writing zip file
const w = await zip.create("new-file.zip", "123");
await w.addFile("package.json");
await w.addFile("index.js", "new-name-in-zip.js");
await w.addDir("native/third_party/minizip");
await w.addDir("native/third_party/minizip", "native/third_party"); // keep minzip
await w.addBuffer("hello.txt", Buffer.from("hello, world!"));
w.close();APIs
zip.open(zipfile, [password]): Promise<Reader>zipfileStringpasswordString
zip.create(zipfile, [password]): Promise<Writer>zipfilestringpasswordString
Reader Objectcount: numberNumber of files in the zipexists(path): booleanitem(index): FileInforead(path): Promise<string>extract(path, dest): Promise<boolean>extract_all(dest_dir, [pattern]): Promise<boolean>close()
Writer ObjectaddBuffer(name, Buffer): Promise<>addDir(dir, [pattern], recursive): Promise<>addFile(file, [new-name]): Promise<>close()
License
MIT license.