]> git.proxmox.com Git - mirror_novnc.git/commitdiff
Split api of inflate
authorNiko Lehto <nikle@cendio.se>
Mon, 3 Feb 2020 09:19:00 +0000 (10:19 +0100)
committerNiko Lehto <nikle@cendio.se>
Mon, 17 Feb 2020 10:29:41 +0000 (11:29 +0100)
Added ability to read data chunk wise.

core/decoders/tight.js
core/inflator.js

index c226b33b09d06d994ae703cda334cc4c8c8c554e..b207419e193d7ea3da88e890fa95fe2460909d27 100644 (file)
@@ -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
index 39db447a10250c9e8d3edbd9a20279a0e1f77bda..c85501ffc2bd6d8f359a4c37e561c53ec019e6dc 100644 (file)
@@ -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.