inflator.partial.js 1.2 KB

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