]>
git.proxmox.com Git - mirror_novnc.git/blob - core/inflator.js
2 * noVNC: HTML5 VNC client
3 * Copyright (C) 2020 The noVNC Authors
4 * Licensed under MPL 2.0 (see LICENSE.txt)
6 * See README.md for usage and integration instructions.
9 import { inflateInit
, inflate
, inflateReset
} from "../vendor/pako/lib/zlib/inflate.js";
10 import ZStream
from "../vendor/pako/lib/zlib/zstream.js";
12 export default class Inflate
{
14 this.strm
= new ZStream();
15 this.chunkSize
= 1024 * 10 * 10;
16 this.strm
.output
= new Uint8Array(this.chunkSize
);
19 inflateInit(this.strm
, this.windowBits
);
22 inflate(data
, expected
) {
23 this.strm
.input
= data
;
24 this.strm
.avail_in
= this.strm
.input
.length
;
25 this.strm
.next_in
= 0;
26 this.strm
.next_out
= 0;
28 // resize our output buffer if it's too small
29 // (we could just use multiple chunks, but that would cause an extra
30 // allocation each time to flatten the chunks)
31 if (expected
> this.chunkSize
) {
32 this.chunkSize
= expected
;
33 this.strm
.output
= new Uint8Array(this.chunkSize
);
36 this.strm
.avail_out
= this.chunkSize
;
38 inflate(this.strm
, 0); // Flush argument not used.
40 if (this.strm
.next_out
!= expected
) {
41 throw new Error("Incomplete zlib block");
44 return new Uint8Array(this.strm
.output
.buffer
, 0, this.strm
.next_out
);
48 inflateReset(this.strm
);