Skip to content

Commit d89e7d7

Browse files
committed
Add an example of how to use zipper.start() and zipper.appendFiles()
1 parent 654e9da commit d89e7d7

File tree

2 files changed

+18
-1
lines changed

2 files changed

+18
-1
lines changed

archive/compress.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -157,7 +157,7 @@ export class Zipper {
157157
* @returns {Promise<Uint8Array>} A Promise that will resolve once the final file has been sent.
158158
* The Promise resolves to an array of bytes of the entire zipped archive.
159159
*/
160-
async start(files, isLastFile = false) {
160+
async start(files = [], isLastFile = false) {
161161
if (this.compressStatus_ !== CompressStatus.NOT_STARTED) {
162162
throw `start() called, but Zipper already started.`;
163163
}

docs/bitjs.archive.md

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -152,6 +152,23 @@ is pretty straightforward and there is no event-based / streaming API.
152152
true /* isLastFile */);
153153
```
154154

155+
If you don't want to have all files in memory at once, you can zip progressively:
156+
157+
```javascript
158+
import { Zipper } from './bitjs/archive/compress.js';
159+
const zipper = new Zipper();
160+
const zipPromise = zipper.start();
161+
// ... some time later
162+
zipper.appendFiles([file1]);
163+
// ... more time later
164+
zipper.appendFiles([file2]);
165+
// ... now we add the last file
166+
zipper.appendFiles([file3], true /* isLastFile */);
167+
168+
const zippedArrayBuffer = await zipPromise;
169+
...
170+
```
171+
155172
## Implementation Details
156173

157174
All you generally need to worry about is calling getUnarchiver(), listen for events, and then `start()`. However, if you are interested in how it works under the covers, read on...

0 commit comments

Comments
 (0)