]>
Commit | Line | Data |
---|---|---|
ae510306 SR |
1 | var zlib = require('pako/lib/zlib/inflate.js'); |
2 | var ZStream = require('pako/lib/zlib/zstream.js'); | |
6940936f | 3 | |
ae510306 | 4 | function Inflate() { |
6940936f SR |
5 | this.strm = new ZStream(); |
6 | this.chunkSize = 1024 * 10 * 10; | |
7 | this.strm.output = new Uint8Array(this.chunkSize); | |
8 | this.windowBits = 5; | |
9 | ||
10 | zlib.inflateInit(this.strm, this.windowBits); | |
11 | }; | |
12 | ||
13 | Inflate.prototype = { | |
c802d931 | 14 | inflate: function (data, flush, expected) { |
6940936f 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 | ||
c802d931 SR |
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 | ||
6940936f SR |
28 | this.strm.avail_out = this.chunkSize; |
29 | ||
30 | zlib.inflate(this.strm, flush); | |
31 | ||
32 | return new Uint8Array(this.strm.output.buffer, 0, this.strm.next_out); | |
33 | }, | |
34 | ||
35 | reset: function () { | |
36 | zlib.inflateReset(this.strm); | |
37 | } | |
38 | }; | |
39 | ||
ae510306 | 40 | module.exports = { Inflate: Inflate }; |