]>
git.proxmox.com Git - mirror_novnc.git/blob - core/deflator.js
ad3d0fb77107dbd5d9d357241ca96e9a302be297
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 { deflateInit
, deflate
} from "../vendor/pako/lib/zlib/deflate.js";
10 import { Z_FULL_FLUSH
} from "../vendor/pako/lib/zlib/deflate.js";
11 import ZStream
from "../vendor/pako/lib/zlib/zstream.js";
13 export default class Deflator
{
15 this.strm
= new ZStream();
16 this.chunkSize
= 1024 * 10 * 10;
17 this.outputBuffer
= new Uint8Array(this.chunkSize
);
20 deflateInit(this.strm
, this.windowBits
);
24 this.strm
.input
= inData
;
25 this.strm
.avail_in
= this.strm
.input
.length
;
26 this.strm
.next_in
= 0;
27 this.strm
.output
= this.outputBuffer
;
28 this.strm
.avail_out
= this.chunkSize
;
29 this.strm
.next_out
= 0;
31 let lastRet
= deflate(this.strm
, Z_FULL_FLUSH
);
32 let outData
= new Uint8Array(this.strm
.output
.buffer
, 0, this.strm
.next_out
);
35 throw new Error("zlib deflate failed");
38 if (this.strm
.avail_in
> 0) {
39 // Read chunks until done
41 let chunks
= [outData
];
42 let totalLen
= outData
.length
;
44 this.strm
.output
= new Uint8Array(this.chunkSize
);
45 this.strm
.next_out
= 0;
46 this.strm
.avail_out
= this.chunkSize
;
48 lastRet
= deflate(this.strm
, Z_FULL_FLUSH
);
51 throw new Error("zlib deflate failed");
54 let chunk
= new Uint8Array(this.strm
.output
.buffer
, 0, this.strm
.next_out
);
55 totalLen
+= chunk
.length
;
57 } while (this.strm
.avail_in
> 0);
59 // Combine chunks into a single data
61 let newData
= new Uint8Array(totalLen
);
64 for (let i
= 0; i
< chunks
.length
; i
++) {
65 newData
.set(chunks
[i
], offset
);
66 offset
+= chunks
[i
].length
;
72 this.strm
.input
= null;
73 this.strm
.avail_in
= 0;
74 this.strm
.next_in
= 0;