0.0.7 • Published 5 years ago

yauzlw v0.0.7

Weekly downloads
14
License
MIT
Repository
github
Last release
5 years ago

Yet Another Unzip Library Wrapper

This package wrap yauzl.

Why Another Wrapper

Because current nodejs unzipper wrapper cannot fulfill my requirements...

User Scenarios

  1. You want to extract the zip (from stream) and don't want to care wtf the content is.
    • See extractEntries/createExtractStream, which extractEntries(destination)/createExtractStream(destination).
  2. 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)
  3. You just want to parse (from stream) some certain KNOWNED entries.
    • See parseEntries/createParseEntriesStream with parseEntries(entries)/createParseEntriesStream(entries)
  4. 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");
    });
0.0.7

5 years ago

0.0.6

5 years ago

0.0.5

5 years ago

0.0.4

5 years ago

0.0.3

5 years ago

0.0.2

5 years ago

0.0.1

5 years ago