Skip to content

Commit

Permalink
Add onUpdate callback
Browse files Browse the repository at this point in the history
lelinhtinh committed Jun 21, 2020
1 parent 8cc94ce commit b9406a5
Showing 3 changed files with 8 additions and 4 deletions.
3 changes: 2 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -118,10 +118,11 @@ Place `<%= image[IMG_ID] %>` inside the chapter's content *(HTML string only)*,
### Generate EPUB `*`

```typescript
jepub.generate(type = 'blob')
jepub.generate(type = 'blob', onUpdate?: metadata => void)
```

- **type**: The type of EPUB to return. See [JSZip type option](https://stuk.github.io/jszip/documentation/api_jszip/generate_async.html#type-option).
- **onUpdate**: _(optional)_ Callback function. See [JSZip onUpdate callback](https://stuk.github.io/jszip/documentation/api_jszip/generate_async.html#onupdate-callback).

### Static methods `+`

5 changes: 4 additions & 1 deletion demo/script.js
Original file line number Diff line number Diff line change
@@ -42,7 +42,10 @@
]);

console.log(jepub);
const blob = await jepub.generate();
const blob = await jepub.generate('blob', metadata => {
console.log('progression: ' + metadata.percent.toFixed(2) + ' %');
if (metadata.currentFile) console.log('current file = ' + metadata.currentFile);
});
console.log(blob);

let url = URL.createObjectURL(blob);
4 changes: 2 additions & 2 deletions src/jepub.js
Original file line number Diff line number Diff line change
@@ -188,7 +188,7 @@ export default class jEpub {
}
}

generate(type = 'blob') {
generate(type = 'blob', onUpdate) {
if (!JSZip.support[type]) throw `This browser does not support ${type}`;

let notes = this._Zip.file('OEBPS/notes.html');
@@ -236,6 +236,6 @@ export default class jEpub {
compressionOptions: {
level: 9
}
});
}, onUpdate);
}
}

0 comments on commit b9406a5

Please sign in to comment.