diff options
author | Niko Lehto <nikle@cendio.se> | 2020-02-03 10:19:00 +0100 |
---|---|---|
committer | Niko Lehto <nikle@cendio.se> | 2020-02-17 11:29:41 +0100 |
commit | 2cee106eee9d01216a627406757beede85341a51 (patch) | |
tree | db7c350bfe33f53568decd51cb32da999f955519 | |
parent | 3cf11004b476b66296714e0d7b85437d40604cc3 (diff) | |
download | novnc-2cee106eee9d01216a627406757beede85341a51.tar.gz |
Split api of inflate
Added ability to read data chunk wise.
-rw-r--r-- | core/decoders/tight.js | 8 | ||||
-rw-r--r-- | core/inflator.js | 19 |
2 files changed, 20 insertions, 7 deletions
diff --git a/core/decoders/tight.js b/core/decoders/tight.js index c226b33..b207419 100644 --- a/core/decoders/tight.js +++ b/core/decoders/tight.js @@ -160,7 +160,9 @@ export default class TightDecoder { return false; } - data = this._zlibs[streamId].inflate(data, uncompressedSize); + this._zlibs[streamId].setInput(data); + data = this._zlibs[streamId].inflate(uncompressedSize); + this._zlibs[streamId].setInput(null); } display.blitRgbImage(x, y, width, height, data, 0, false); @@ -205,7 +207,9 @@ export default class TightDecoder { return false; } - data = this._zlibs[streamId].inflate(data, uncompressedSize); + this._zlibs[streamId].setInput(data); + data = this._zlibs[streamId].inflate(uncompressedSize); + this._zlibs[streamId].setInput(null); } // Convert indexed (palette based) image data to RGB diff --git a/core/inflator.js b/core/inflator.js index 39db447..c85501f 100644 --- a/core/inflator.js +++ b/core/inflator.js @@ -19,12 +19,20 @@ export default class Inflate { inflateInit(this.strm, this.windowBits); } - inflate(data, expected) { - this.strm.input = data; - this.strm.avail_in = this.strm.input.length; - this.strm.next_in = 0; - this.strm.next_out = 0; + setInput(data) { + if (!data) { + //FIXME: flush remaining data. + this.strm.input = null; + this.strm.avail_in = 0; + this.strm.next_in = 0; + } else { + this.strm.input = data; + this.strm.avail_in = this.strm.input.length; + this.strm.next_in = 0; + } + } + inflate(expected) { // 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) @@ -33,6 +41,7 @@ export default class Inflate { this.strm.output = new Uint8Array(this.chunkSize); } + this.strm.next_out = 0; this.strm.avail_out = this.chunkSize; let ret = inflate(this.strm, 0); // Flush argument not used. |