]>
Commit | Line | Data |
---|---|---|
fba220c6 SR |
1 | import { inflateInit, inflate, inflateReset } from "../vendor/pako/lib/zlib/inflate.js"; |
2 | import ZStream from "../vendor/pako/lib/zlib/zstream.js"; | |
ae510306 | 3 | |
0e4808bf JD |
4 | export default class Inflate { |
5 | constructor() { | |
6 | this.strm = new ZStream(); | |
7 | this.chunkSize = 1024 * 10 * 10; | |
8 | this.strm.output = new Uint8Array(this.chunkSize); | |
9 | this.windowBits = 5; | |
10 | ||
11 | inflateInit(this.strm, this.windowBits); | |
12 | } | |
13 | ||
14 | inflate(data, flush, expected) { | |
ae510306 SR |
15 | this.strm.input = data; |
16 | this.strm.avail_in = this.strm.input.length; | |
17 | this.strm.next_in = 0; | |
18 | this.strm.next_out = 0; | |
19 | ||
20 | // resize our output buffer if it's too small | |
21 | // (we could just use multiple chunks, but that would cause an extra | |
22 | // allocation each time to flatten the chunks) | |
23 | if (expected > this.chunkSize) { | |
24 | this.chunkSize = expected; | |
25 | this.strm.output = new Uint8Array(this.chunkSize); | |
26 | } | |
27 | ||
28 | this.strm.avail_out = this.chunkSize; | |
29 | ||
fba220c6 | 30 | inflate(this.strm, flush); |
ae510306 SR |
31 | |
32 | return new Uint8Array(this.strm.output.buffer, 0, this.strm.next_out); | |
0e4808bf | 33 | } |
ae510306 | 34 | |
0e4808bf | 35 | reset() { |
fba220c6 | 36 | inflateReset(this.strm); |
6940936f | 37 | } |
8727f598 | 38 | } |