2018-08-27 12:30:50 +00:00
|
|
|
import { inflateInit, inflate, inflateReset } from "../vendor/pako/lib/zlib/inflate.js";
|
|
|
|
import ZStream from "../vendor/pako/lib/zlib/zstream.js";
|
2018-08-14 12:11:49 +00:00
|
|
|
|
2019-06-24 11:26:25 +00:00
|
|
|
export default class Inflate {
|
|
|
|
constructor() {
|
|
|
|
this.strm = new ZStream();
|
|
|
|
this.chunkSize = 1024 * 10 * 10;
|
|
|
|
this.strm.output = new Uint8Array(this.chunkSize);
|
|
|
|
this.windowBits = 5;
|
|
|
|
|
|
|
|
inflateInit(this.strm, this.windowBits);
|
|
|
|
}
|
|
|
|
|
|
|
|
inflate(data, flush, expected) {
|
2018-08-14 12:11:49 +00:00
|
|
|
this.strm.input = data;
|
|
|
|
this.strm.avail_in = this.strm.input.length;
|
|
|
|
this.strm.next_in = 0;
|
|
|
|
this.strm.next_out = 0;
|
|
|
|
|
|
|
|
// resize our output buffer if it's too small
|
|
|
|
// (we could just use multiple chunks, but that would cause an extra
|
|
|
|
// allocation each time to flatten the chunks)
|
|
|
|
if (expected > this.chunkSize) {
|
|
|
|
this.chunkSize = expected;
|
|
|
|
this.strm.output = new Uint8Array(this.chunkSize);
|
|
|
|
}
|
|
|
|
|
|
|
|
this.strm.avail_out = this.chunkSize;
|
|
|
|
|
2018-08-27 12:30:50 +00:00
|
|
|
inflate(this.strm, flush);
|
2018-08-14 12:11:49 +00:00
|
|
|
|
|
|
|
return new Uint8Array(this.strm.output.buffer, 0, this.strm.next_out);
|
2019-06-24 11:26:25 +00:00
|
|
|
}
|
2018-08-14 12:11:49 +00:00
|
|
|
|
2019-06-24 11:26:25 +00:00
|
|
|
reset() {
|
2018-08-27 12:30:50 +00:00
|
|
|
inflateReset(this.strm);
|
2018-08-14 12:11:49 +00:00
|
|
|
}
|
2019-06-24 11:26:25 +00:00
|
|
|
}
|