0.0.7 • Published 5 years ago
yauzlw v0.0.7
Yet Another Unzip Library Wrapper
This package wrap yauzl.
Why Another Wrapper
Because current nodejs unzipper wrapper cannot fulfill my requirements...
User Scenarios
- You want to extract the zip (from stream) and don't want to care wtf the content is.
- See
extractEntries/createExtractStream
, whichextractEntries(destination)/createExtractStream(destination)
.
- See
- You want to extract the zip (from stream) and you know which entries you want. See
extractEntries/createExtractStream
.- If you know which exact entries you want, use
extractEntries(destination, entries)/createExtractStream(destination, entries)
. - If you don't know what specific entries you want, use
extractEntries(destination, filter)/createExtractStream(destination, filter)
- If you know which exact entries you want, use
- You just want to parse (from stream) some certain KNOWNED entries.
- See
parseEntries/createParseEntriesStream
withparseEntries(entries)/createParseEntriesStream(entries)
- See
- The final mixture case is you want to parse certain entries' content. But they don't know the exact name of the entries. See
walkEntries/createWalkEntriesStream
.
This will terminate the iteration of entires if this function return true
or Promise<boolean>
with result true
.
Detailed Example
import { createExtractStream, createParseEntriesStream, walkEntries, bufferEntry } from 'yauzlw'
// extract stream
yourZipStream
.pipe(createExtractStream('./unzipped-folder'))
.promise()
.then(() => {
console.log("./unzipped-folder will have the unzipped content!");
});
// parse stream
yourZipStream
.pipe(createParseEntriesStream(['your-entry-name']))
.promise()
.then((entries) => bufferEntry(entries.file, entries.entries['your-entry-name'])) // handle your entry here
.then(buf => buf.toString())
.then(console.log);
walkEntries(zipfile, (entry) => {
// handle entry here
return true; // this will terminate the iteration
});
walkEntries(zipfile, (entry) => {
// handle entry here
return Promise.resolve(true); // this will terminate the iteration
});
// use walk with stream, this will terminate when it see first entry's name ended with index.js
yourZipStream
.pipe(createWalkEntriesStream((entry) => {
return new Promise((resolve, reject) => {
if (entry.fileName.endsWith("index.js")) {
resolve(true);
} else {
resolve(false);
}
})
}))
.promise()
.then(() => {
console.log("DONE");
});