Skip to content

Commit

Permalink
docs: add more usage examples entryHandler and rules (#7)
Browse files Browse the repository at this point in the history
fix builder banner
  • Loading branch information
Mik authored Dec 13, 2019
1 parent 5acf1b4 commit 71b73dd
Showing 1 changed file with 58 additions and 1 deletion.
59 changes: 58 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# anzip [![Build Status](https://travis-ci.com/mikbry/anzip.svg?token=mRB1zwsyoRAKcamR2qpU&branch=master)](https://travis-ci.com/mikbry/anzip) [![codecov](https://codecov.io/gh/mikbry/anzip/branch/master/graph/badge.svg?token=K4P0vnM5fh)](https://codecov.io/gh/mikbry/anzip)
# anzip [![Build Status](https://travis-ci.com/mikbry/anzip.svg?token=mRB1zwsyoRAKcamR2qpU)](https://travis-ci.com/mikbry/anzip) [![codecov](https://codecov.io/gh/mikbry/anzip/branch/master/graph/badge.svg?token=K4P0vnM5fh)](https://codecov.io/gh/mikbry/anzip)
> Anzip is a library to unzip file archive for Node using only one async function.

Expand Down Expand Up @@ -73,6 +73,63 @@ console.log('duration=', output.duration);
console.log('content=', output.files[0].content);
```
> Extract with an entryHandler to fliter entry
```
const outputPath = './path';
const entryHandler = async entry => {
let resp = true;
const fn = entry.name;
if (fn.endsWith('dummy.pdf')) {
try {
await entry.saveTo(outputPath);
resp = false;
} catch (e) {
//
}
}
return resp;
};
const output = await anzip('file.zip',
outputPath,
{ pattern: /(^(?!\.))(.+(.png|.jpeg|.jpg|.svg|.pdf|.json))$/i,, outputPath: './', entryHandler, outputContent: true });
console.log('duration=', output.duration);
// ./path/dummy.pdf should be saved
```
> Extract using 2 rules and an entryHandler in one to fliter entry
```
const outputPath = './path';
const entryHandler = async entry => {
let resp = true;
const fn = entry.name;
if (fn.endsWith('dummy.pdf')) {
try {
await entry.saveTo(outputPath);
resp = false;
} catch (e) {
//
}
}
return resp;
};
const output = await anzip('file.zip',
outputPath,
pattern: /(^(?!\.))(.+(.png|.jpeg|.jpg|.svg|.pdf|.json))$/i,
flattenPath: true,
disableSave: true,
disableOutput: true,
rules: [
{ pattern: /(^(?!\.))(test.json)$/i, outputContent: true },
{ pattern: /(^(?!\.))(.+(.png|.jpeg|.jpg|.svg|.pdf))$/i, entryHandler },
],
});
console.log('duration=', output.duration);
// ./path/dummy.pdf should be saved
```
---
### Documentation
Expand Down

0 comments on commit 71b73dd

Please sign in to comment.