inflator.js 1.2 KB

1234567891011121314151617181920212223242526272829303132333435363738
  1. import { inflateInit, inflate, inflateReset } from "../vendor/pako/lib/zlib/inflate.js";
  2. import ZStream from "../vendor/pako/lib/zlib/zstream.js";
  3. Inflate.prototype = {
  4. inflate: function (data, flush, expected) {
  5. this.strm.input = data;
  6. this.strm.avail_in = this.strm.input.length;
  7. this.strm.next_in = 0;
  8. this.strm.next_out = 0;
  9. // resize our output buffer if it's too small
  10. // (we could just use multiple chunks, but that would cause an extra
  11. // allocation each time to flatten the chunks)
  12. if (expected > this.chunkSize) {
  13. this.chunkSize = expected;
  14. this.strm.output = new Uint8Array(this.chunkSize);
  15. }
  16. this.strm.avail_out = this.chunkSize;
  17. inflate(this.strm, flush);
  18. return new Uint8Array(this.strm.output.buffer, 0, this.strm.next_out);
  19. },
  20. reset: function () {
  21. inflateReset(this.strm);
  22. }
  23. };
  24. export default function Inflate() {
  25. this.strm = new ZStream();
  26. this.chunkSize = 1024 * 10 * 10;
  27. this.strm.output = new Uint8Array(this.chunkSize);
  28. this.windowBits = 5;
  29. inflateInit(this.strm, this.windowBits);
  30. };