susi-qemu 0.0.2 → 0.0.5
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/bin/susi +9 -4
- data/lib/disk.rb +7 -5
- data/lib/novnc/core/base64.js +104 -0
- data/lib/novnc/core/crypto/aes.js +178 -0
- data/lib/novnc/core/crypto/bigint.js +34 -0
- data/lib/novnc/core/crypto/crypto.js +90 -0
- data/lib/novnc/core/crypto/des.js +330 -0
- data/lib/novnc/core/crypto/dh.js +55 -0
- data/lib/novnc/core/crypto/md5.js +82 -0
- data/lib/novnc/core/crypto/rsa.js +132 -0
- data/lib/novnc/core/decoders/copyrect.js +27 -0
- data/lib/novnc/core/decoders/h264.js +321 -0
- data/lib/novnc/core/decoders/hextile.js +181 -0
- data/lib/novnc/core/decoders/jpeg.js +146 -0
- data/lib/novnc/core/decoders/raw.js +59 -0
- data/lib/novnc/core/decoders/rre.js +44 -0
- data/lib/novnc/core/decoders/tight.js +393 -0
- data/lib/novnc/core/decoders/tightpng.js +27 -0
- data/lib/novnc/core/decoders/zlib.js +51 -0
- data/lib/novnc/core/decoders/zrle.js +185 -0
- data/lib/novnc/core/deflator.js +84 -0
- data/lib/novnc/core/display.js +575 -0
- data/lib/novnc/core/encodings.js +53 -0
- data/lib/novnc/core/inflator.js +65 -0
- data/lib/novnc/core/input/domkeytable.js +311 -0
- data/lib/novnc/core/input/fixedkeys.js +129 -0
- data/lib/novnc/core/input/gesturehandler.js +567 -0
- data/lib/novnc/core/input/keyboard.js +294 -0
- data/lib/novnc/core/input/keysym.js +616 -0
- data/lib/novnc/core/input/keysymdef.js +688 -0
- data/lib/novnc/core/input/util.js +191 -0
- data/lib/novnc/core/input/vkeys.js +116 -0
- data/lib/novnc/core/input/xtscancodes.js +173 -0
- data/lib/novnc/core/ra2.js +312 -0
- data/lib/novnc/core/rfb.js +3257 -0
- data/lib/novnc/core/util/browser.js +172 -0
- data/lib/novnc/core/util/cursor.js +249 -0
- data/lib/novnc/core/util/element.js +32 -0
- data/lib/novnc/core/util/events.js +138 -0
- data/lib/novnc/core/util/eventtarget.js +35 -0
- data/lib/novnc/core/util/int.js +15 -0
- data/lib/novnc/core/util/logging.js +56 -0
- data/lib/novnc/core/util/strings.js +28 -0
- data/lib/novnc/core/websock.js +365 -0
- data/lib/novnc/screen.html +21 -0
- data/lib/novnc/vendor/pako/lib/utils/common.js +45 -0
- data/lib/novnc/vendor/pako/lib/zlib/adler32.js +27 -0
- data/lib/novnc/vendor/pako/lib/zlib/constants.js +47 -0
- data/lib/novnc/vendor/pako/lib/zlib/crc32.js +36 -0
- data/lib/novnc/vendor/pako/lib/zlib/deflate.js +1846 -0
- data/lib/novnc/vendor/pako/lib/zlib/gzheader.js +35 -0
- data/lib/novnc/vendor/pako/lib/zlib/inffast.js +324 -0
- data/lib/novnc/vendor/pako/lib/zlib/inflate.js +1527 -0
- data/lib/novnc/vendor/pako/lib/zlib/inftrees.js +322 -0
- data/lib/novnc/vendor/pako/lib/zlib/messages.js +11 -0
- data/lib/novnc/vendor/pako/lib/zlib/trees.js +1195 -0
- data/lib/novnc/vendor/pako/lib/zlib/zstream.js +24 -0
- data/lib/output.rb +11 -0
- data/lib/qmp.rb +6 -0
- data/lib/ssh.rb +3 -1
- data/lib/susi.rb +7 -6
- data/lib/version.rb +1 -1
- data/lib/vm.rb +44 -26
- data/lib/vnc.rb +34 -31
- metadata +57 -1
@@ -0,0 +1,28 @@
|
|
1
|
+
/*
|
2
|
+
* noVNC: HTML5 VNC client
|
3
|
+
* Copyright (C) 2019 The noVNC Authors
|
4
|
+
* Licensed under MPL 2.0 (see LICENSE.txt)
|
5
|
+
*
|
6
|
+
* See README.md for usage and integration instructions.
|
7
|
+
*/
|
8
|
+
|
9
|
+
// Decode from UTF-8
|
10
|
+
export function decodeUTF8(utf8string, allowLatin1=false) {
|
11
|
+
try {
|
12
|
+
return decodeURIComponent(escape(utf8string));
|
13
|
+
} catch (e) {
|
14
|
+
if (e instanceof URIError) {
|
15
|
+
if (allowLatin1) {
|
16
|
+
// If we allow Latin1 we can ignore any decoding fails
|
17
|
+
// and in these cases return the original string
|
18
|
+
return utf8string;
|
19
|
+
}
|
20
|
+
}
|
21
|
+
throw e;
|
22
|
+
}
|
23
|
+
}
|
24
|
+
|
25
|
+
// Encode to UTF-8
|
26
|
+
export function encodeUTF8(DOMString) {
|
27
|
+
return unescape(encodeURIComponent(DOMString));
|
28
|
+
}
|
@@ -0,0 +1,365 @@
|
|
1
|
+
/*
|
2
|
+
* Websock: high-performance buffering wrapper
|
3
|
+
* Copyright (C) 2019 The noVNC Authors
|
4
|
+
* Licensed under MPL 2.0 (see LICENSE.txt)
|
5
|
+
*
|
6
|
+
* Websock is similar to the standard WebSocket / RTCDataChannel object
|
7
|
+
* but with extra buffer handling.
|
8
|
+
*
|
9
|
+
* Websock has built-in receive queue buffering; the message event
|
10
|
+
* does not contain actual data but is simply a notification that
|
11
|
+
* there is new data available. Several rQ* methods are available to
|
12
|
+
* read binary data off of the receive queue.
|
13
|
+
*/
|
14
|
+
|
15
|
+
import * as Log from './util/logging.js';
|
16
|
+
|
17
|
+
// this has performance issues in some versions Chromium, and
|
18
|
+
// doesn't gain a tremendous amount of performance increase in Firefox
|
19
|
+
// at the moment. It may be valuable to turn it on in the future.
|
20
|
+
const MAX_RQ_GROW_SIZE = 40 * 1024 * 1024; // 40 MiB
|
21
|
+
|
22
|
+
// Constants pulled from RTCDataChannelState enum
|
23
|
+
// https://developer.mozilla.org/en-US/docs/Web/API/RTCDataChannel/readyState#RTCDataChannelState_enum
|
24
|
+
const DataChannel = {
|
25
|
+
CONNECTING: "connecting",
|
26
|
+
OPEN: "open",
|
27
|
+
CLOSING: "closing",
|
28
|
+
CLOSED: "closed"
|
29
|
+
};
|
30
|
+
|
31
|
+
const ReadyStates = {
|
32
|
+
CONNECTING: [WebSocket.CONNECTING, DataChannel.CONNECTING],
|
33
|
+
OPEN: [WebSocket.OPEN, DataChannel.OPEN],
|
34
|
+
CLOSING: [WebSocket.CLOSING, DataChannel.CLOSING],
|
35
|
+
CLOSED: [WebSocket.CLOSED, DataChannel.CLOSED],
|
36
|
+
};
|
37
|
+
|
38
|
+
// Properties a raw channel must have, WebSocket and RTCDataChannel are two examples
|
39
|
+
const rawChannelProps = [
|
40
|
+
"send",
|
41
|
+
"close",
|
42
|
+
"binaryType",
|
43
|
+
"onerror",
|
44
|
+
"onmessage",
|
45
|
+
"onopen",
|
46
|
+
"protocol",
|
47
|
+
"readyState",
|
48
|
+
];
|
49
|
+
|
50
|
+
export default class Websock {
|
51
|
+
constructor() {
|
52
|
+
this._websocket = null; // WebSocket or RTCDataChannel object
|
53
|
+
|
54
|
+
this._rQi = 0; // Receive queue index
|
55
|
+
this._rQlen = 0; // Next write position in the receive queue
|
56
|
+
this._rQbufferSize = 1024 * 1024 * 4; // Receive queue buffer size (4 MiB)
|
57
|
+
// called in init: this._rQ = new Uint8Array(this._rQbufferSize);
|
58
|
+
this._rQ = null; // Receive queue
|
59
|
+
|
60
|
+
this._sQbufferSize = 1024 * 10; // 10 KiB
|
61
|
+
// called in init: this._sQ = new Uint8Array(this._sQbufferSize);
|
62
|
+
this._sQlen = 0;
|
63
|
+
this._sQ = null; // Send queue
|
64
|
+
|
65
|
+
this._eventHandlers = {
|
66
|
+
message: () => {},
|
67
|
+
open: () => {},
|
68
|
+
close: () => {},
|
69
|
+
error: () => {}
|
70
|
+
};
|
71
|
+
}
|
72
|
+
|
73
|
+
// Getters and Setters
|
74
|
+
|
75
|
+
get readyState() {
|
76
|
+
let subState;
|
77
|
+
|
78
|
+
if (this._websocket === null) {
|
79
|
+
return "unused";
|
80
|
+
}
|
81
|
+
|
82
|
+
subState = this._websocket.readyState;
|
83
|
+
|
84
|
+
if (ReadyStates.CONNECTING.includes(subState)) {
|
85
|
+
return "connecting";
|
86
|
+
} else if (ReadyStates.OPEN.includes(subState)) {
|
87
|
+
return "open";
|
88
|
+
} else if (ReadyStates.CLOSING.includes(subState)) {
|
89
|
+
return "closing";
|
90
|
+
} else if (ReadyStates.CLOSED.includes(subState)) {
|
91
|
+
return "closed";
|
92
|
+
}
|
93
|
+
|
94
|
+
return "unknown";
|
95
|
+
}
|
96
|
+
|
97
|
+
// Receive Queue
|
98
|
+
rQpeek8() {
|
99
|
+
return this._rQ[this._rQi];
|
100
|
+
}
|
101
|
+
|
102
|
+
rQskipBytes(bytes) {
|
103
|
+
this._rQi += bytes;
|
104
|
+
}
|
105
|
+
|
106
|
+
rQshift8() {
|
107
|
+
return this._rQshift(1);
|
108
|
+
}
|
109
|
+
|
110
|
+
rQshift16() {
|
111
|
+
return this._rQshift(2);
|
112
|
+
}
|
113
|
+
|
114
|
+
rQshift32() {
|
115
|
+
return this._rQshift(4);
|
116
|
+
}
|
117
|
+
|
118
|
+
// TODO(directxman12): test performance with these vs a DataView
|
119
|
+
_rQshift(bytes) {
|
120
|
+
let res = 0;
|
121
|
+
for (let byte = bytes - 1; byte >= 0; byte--) {
|
122
|
+
res += this._rQ[this._rQi++] << (byte * 8);
|
123
|
+
}
|
124
|
+
return res >>> 0;
|
125
|
+
}
|
126
|
+
|
127
|
+
rQshiftStr(len) {
|
128
|
+
let str = "";
|
129
|
+
// Handle large arrays in steps to avoid long strings on the stack
|
130
|
+
for (let i = 0; i < len; i += 4096) {
|
131
|
+
let part = this.rQshiftBytes(Math.min(4096, len - i), false);
|
132
|
+
str += String.fromCharCode.apply(null, part);
|
133
|
+
}
|
134
|
+
return str;
|
135
|
+
}
|
136
|
+
|
137
|
+
rQshiftBytes(len, copy=true) {
|
138
|
+
this._rQi += len;
|
139
|
+
if (copy) {
|
140
|
+
return this._rQ.slice(this._rQi - len, this._rQi);
|
141
|
+
} else {
|
142
|
+
return this._rQ.subarray(this._rQi - len, this._rQi);
|
143
|
+
}
|
144
|
+
}
|
145
|
+
|
146
|
+
rQshiftTo(target, len) {
|
147
|
+
// TODO: make this just use set with views when using a ArrayBuffer to store the rQ
|
148
|
+
target.set(new Uint8Array(this._rQ.buffer, this._rQi, len));
|
149
|
+
this._rQi += len;
|
150
|
+
}
|
151
|
+
|
152
|
+
rQpeekBytes(len, copy=true) {
|
153
|
+
if (copy) {
|
154
|
+
return this._rQ.slice(this._rQi, this._rQi + len);
|
155
|
+
} else {
|
156
|
+
return this._rQ.subarray(this._rQi, this._rQi + len);
|
157
|
+
}
|
158
|
+
}
|
159
|
+
|
160
|
+
// Check to see if we must wait for 'num' bytes (default to FBU.bytes)
|
161
|
+
// to be available in the receive queue. Return true if we need to
|
162
|
+
// wait (and possibly print a debug message), otherwise false.
|
163
|
+
rQwait(msg, num, goback) {
|
164
|
+
if (this._rQlen - this._rQi < num) {
|
165
|
+
if (goback) {
|
166
|
+
if (this._rQi < goback) {
|
167
|
+
throw new Error("rQwait cannot backup " + goback + " bytes");
|
168
|
+
}
|
169
|
+
this._rQi -= goback;
|
170
|
+
}
|
171
|
+
return true; // true means need more data
|
172
|
+
}
|
173
|
+
return false;
|
174
|
+
}
|
175
|
+
|
176
|
+
// Send Queue
|
177
|
+
|
178
|
+
sQpush8(num) {
|
179
|
+
this._sQensureSpace(1);
|
180
|
+
this._sQ[this._sQlen++] = num;
|
181
|
+
}
|
182
|
+
|
183
|
+
sQpush16(num) {
|
184
|
+
this._sQensureSpace(2);
|
185
|
+
this._sQ[this._sQlen++] = (num >> 8) & 0xff;
|
186
|
+
this._sQ[this._sQlen++] = (num >> 0) & 0xff;
|
187
|
+
}
|
188
|
+
|
189
|
+
sQpush32(num) {
|
190
|
+
this._sQensureSpace(4);
|
191
|
+
this._sQ[this._sQlen++] = (num >> 24) & 0xff;
|
192
|
+
this._sQ[this._sQlen++] = (num >> 16) & 0xff;
|
193
|
+
this._sQ[this._sQlen++] = (num >> 8) & 0xff;
|
194
|
+
this._sQ[this._sQlen++] = (num >> 0) & 0xff;
|
195
|
+
}
|
196
|
+
|
197
|
+
sQpushString(str) {
|
198
|
+
let bytes = str.split('').map(chr => chr.charCodeAt(0));
|
199
|
+
this.sQpushBytes(new Uint8Array(bytes));
|
200
|
+
}
|
201
|
+
|
202
|
+
sQpushBytes(bytes) {
|
203
|
+
for (let offset = 0;offset < bytes.length;) {
|
204
|
+
this._sQensureSpace(1);
|
205
|
+
|
206
|
+
let chunkSize = this._sQbufferSize - this._sQlen;
|
207
|
+
if (chunkSize > bytes.length - offset) {
|
208
|
+
chunkSize = bytes.length - offset;
|
209
|
+
}
|
210
|
+
|
211
|
+
this._sQ.set(bytes.subarray(offset, offset + chunkSize), this._sQlen);
|
212
|
+
this._sQlen += chunkSize;
|
213
|
+
offset += chunkSize;
|
214
|
+
}
|
215
|
+
}
|
216
|
+
|
217
|
+
flush() {
|
218
|
+
if (this._sQlen > 0 && this.readyState === 'open') {
|
219
|
+
this._websocket.send(new Uint8Array(this._sQ.buffer, 0, this._sQlen));
|
220
|
+
this._sQlen = 0;
|
221
|
+
}
|
222
|
+
}
|
223
|
+
|
224
|
+
_sQensureSpace(bytes) {
|
225
|
+
if (this._sQbufferSize - this._sQlen < bytes) {
|
226
|
+
this.flush();
|
227
|
+
}
|
228
|
+
}
|
229
|
+
|
230
|
+
// Event Handlers
|
231
|
+
off(evt) {
|
232
|
+
this._eventHandlers[evt] = () => {};
|
233
|
+
}
|
234
|
+
|
235
|
+
on(evt, handler) {
|
236
|
+
this._eventHandlers[evt] = handler;
|
237
|
+
}
|
238
|
+
|
239
|
+
_allocateBuffers() {
|
240
|
+
this._rQ = new Uint8Array(this._rQbufferSize);
|
241
|
+
this._sQ = new Uint8Array(this._sQbufferSize);
|
242
|
+
}
|
243
|
+
|
244
|
+
init() {
|
245
|
+
this._allocateBuffers();
|
246
|
+
this._rQi = 0;
|
247
|
+
this._websocket = null;
|
248
|
+
}
|
249
|
+
|
250
|
+
open(uri, protocols) {
|
251
|
+
this.attach(new WebSocket(uri, protocols));
|
252
|
+
}
|
253
|
+
|
254
|
+
attach(rawChannel) {
|
255
|
+
this.init();
|
256
|
+
|
257
|
+
// Must get object and class methods to be compatible with the tests.
|
258
|
+
const channelProps = [...Object.keys(rawChannel), ...Object.getOwnPropertyNames(Object.getPrototypeOf(rawChannel))];
|
259
|
+
for (let i = 0; i < rawChannelProps.length; i++) {
|
260
|
+
const prop = rawChannelProps[i];
|
261
|
+
if (channelProps.indexOf(prop) < 0) {
|
262
|
+
throw new Error('Raw channel missing property: ' + prop);
|
263
|
+
}
|
264
|
+
}
|
265
|
+
|
266
|
+
this._websocket = rawChannel;
|
267
|
+
this._websocket.binaryType = "arraybuffer";
|
268
|
+
this._websocket.onmessage = this._recvMessage.bind(this);
|
269
|
+
|
270
|
+
this._websocket.onopen = () => {
|
271
|
+
Log.Debug('>> WebSock.onopen');
|
272
|
+
if (this._websocket.protocol) {
|
273
|
+
Log.Info("Server choose sub-protocol: " + this._websocket.protocol);
|
274
|
+
}
|
275
|
+
|
276
|
+
this._eventHandlers.open();
|
277
|
+
Log.Debug("<< WebSock.onopen");
|
278
|
+
};
|
279
|
+
|
280
|
+
this._websocket.onclose = (e) => {
|
281
|
+
Log.Debug(">> WebSock.onclose");
|
282
|
+
this._eventHandlers.close(e);
|
283
|
+
Log.Debug("<< WebSock.onclose");
|
284
|
+
};
|
285
|
+
|
286
|
+
this._websocket.onerror = (e) => {
|
287
|
+
Log.Debug(">> WebSock.onerror: " + e);
|
288
|
+
this._eventHandlers.error(e);
|
289
|
+
Log.Debug("<< WebSock.onerror: " + e);
|
290
|
+
};
|
291
|
+
}
|
292
|
+
|
293
|
+
close() {
|
294
|
+
if (this._websocket) {
|
295
|
+
if (this.readyState === 'connecting' ||
|
296
|
+
this.readyState === 'open') {
|
297
|
+
Log.Info("Closing WebSocket connection");
|
298
|
+
this._websocket.close();
|
299
|
+
}
|
300
|
+
|
301
|
+
this._websocket.onmessage = () => {};
|
302
|
+
}
|
303
|
+
}
|
304
|
+
|
305
|
+
// private methods
|
306
|
+
|
307
|
+
// We want to move all the unread data to the start of the queue,
|
308
|
+
// e.g. compacting.
|
309
|
+
// The function also expands the receive que if needed, and for
|
310
|
+
// performance reasons we combine these two actions to avoid
|
311
|
+
// unnecessary copying.
|
312
|
+
_expandCompactRQ(minFit) {
|
313
|
+
// if we're using less than 1/8th of the buffer even with the incoming bytes, compact in place
|
314
|
+
// instead of resizing
|
315
|
+
const requiredBufferSize = (this._rQlen - this._rQi + minFit) * 8;
|
316
|
+
const resizeNeeded = this._rQbufferSize < requiredBufferSize;
|
317
|
+
|
318
|
+
if (resizeNeeded) {
|
319
|
+
// Make sure we always *at least* double the buffer size, and have at least space for 8x
|
320
|
+
// the current amount of data
|
321
|
+
this._rQbufferSize = Math.max(this._rQbufferSize * 2, requiredBufferSize);
|
322
|
+
}
|
323
|
+
|
324
|
+
// we don't want to grow unboundedly
|
325
|
+
if (this._rQbufferSize > MAX_RQ_GROW_SIZE) {
|
326
|
+
this._rQbufferSize = MAX_RQ_GROW_SIZE;
|
327
|
+
if (this._rQbufferSize - (this._rQlen - this._rQi) < minFit) {
|
328
|
+
throw new Error("Receive Queue buffer exceeded " + MAX_RQ_GROW_SIZE + " bytes, and the new message could not fit");
|
329
|
+
}
|
330
|
+
}
|
331
|
+
|
332
|
+
if (resizeNeeded) {
|
333
|
+
const oldRQbuffer = this._rQ.buffer;
|
334
|
+
this._rQ = new Uint8Array(this._rQbufferSize);
|
335
|
+
this._rQ.set(new Uint8Array(oldRQbuffer, this._rQi, this._rQlen - this._rQi));
|
336
|
+
} else {
|
337
|
+
this._rQ.copyWithin(0, this._rQi, this._rQlen);
|
338
|
+
}
|
339
|
+
|
340
|
+
this._rQlen = this._rQlen - this._rQi;
|
341
|
+
this._rQi = 0;
|
342
|
+
}
|
343
|
+
|
344
|
+
// push arraybuffer values onto the end of the receive que
|
345
|
+
_recvMessage(e) {
|
346
|
+
if (this._rQlen == this._rQi) {
|
347
|
+
// All data has now been processed, this means we
|
348
|
+
// can reset the receive queue.
|
349
|
+
this._rQlen = 0;
|
350
|
+
this._rQi = 0;
|
351
|
+
}
|
352
|
+
const u8 = new Uint8Array(e.data);
|
353
|
+
if (u8.length > this._rQbufferSize - this._rQlen) {
|
354
|
+
this._expandCompactRQ(u8.length);
|
355
|
+
}
|
356
|
+
this._rQ.set(u8, this._rQlen);
|
357
|
+
this._rQlen += u8.length;
|
358
|
+
|
359
|
+
if (this._rQlen - this._rQi > 0) {
|
360
|
+
this._eventHandlers.message();
|
361
|
+
} else {
|
362
|
+
Log.Debug("Ignoring empty message");
|
363
|
+
}
|
364
|
+
}
|
365
|
+
}
|
@@ -0,0 +1,21 @@
|
|
1
|
+
<html>
|
2
|
+
<head>
|
3
|
+
<title>susi</title>
|
4
|
+
<script type="module">
|
5
|
+
import RFB from './core/rfb.js';
|
6
|
+
let host = '###HOST###';
|
7
|
+
let port = '###PORT###';
|
8
|
+
|
9
|
+
let rfb = new RFB(
|
10
|
+
document.getElementById('screen'),
|
11
|
+
'ws://' + host + ':' + port,
|
12
|
+
{});
|
13
|
+
</script>
|
14
|
+
</head>
|
15
|
+
<body>
|
16
|
+
<div>
|
17
|
+
<a href="###TOKEN###.close.html">close</a>
|
18
|
+
</div>
|
19
|
+
<div id="screen"></div>
|
20
|
+
</body>
|
21
|
+
</html>
|
@@ -0,0 +1,45 @@
|
|
1
|
+
// reduce buffer size, avoiding mem copy
|
2
|
+
export function shrinkBuf (buf, size) {
|
3
|
+
if (buf.length === size) { return buf; }
|
4
|
+
if (buf.subarray) { return buf.subarray(0, size); }
|
5
|
+
buf.length = size;
|
6
|
+
return buf;
|
7
|
+
};
|
8
|
+
|
9
|
+
|
10
|
+
export function arraySet (dest, src, src_offs, len, dest_offs) {
|
11
|
+
if (src.subarray && dest.subarray) {
|
12
|
+
dest.set(src.subarray(src_offs, src_offs + len), dest_offs);
|
13
|
+
return;
|
14
|
+
}
|
15
|
+
// Fallback to ordinary array
|
16
|
+
for (var i = 0; i < len; i++) {
|
17
|
+
dest[dest_offs + i] = src[src_offs + i];
|
18
|
+
}
|
19
|
+
}
|
20
|
+
|
21
|
+
// Join array of chunks to single array.
|
22
|
+
export function flattenChunks (chunks) {
|
23
|
+
var i, l, len, pos, chunk, result;
|
24
|
+
|
25
|
+
// calculate data length
|
26
|
+
len = 0;
|
27
|
+
for (i = 0, l = chunks.length; i < l; i++) {
|
28
|
+
len += chunks[i].length;
|
29
|
+
}
|
30
|
+
|
31
|
+
// join chunks
|
32
|
+
result = new Uint8Array(len);
|
33
|
+
pos = 0;
|
34
|
+
for (i = 0, l = chunks.length; i < l; i++) {
|
35
|
+
chunk = chunks[i];
|
36
|
+
result.set(chunk, pos);
|
37
|
+
pos += chunk.length;
|
38
|
+
}
|
39
|
+
|
40
|
+
return result;
|
41
|
+
}
|
42
|
+
|
43
|
+
export var Buf8 = Uint8Array;
|
44
|
+
export var Buf16 = Uint16Array;
|
45
|
+
export var Buf32 = Int32Array;
|
@@ -0,0 +1,27 @@
|
|
1
|
+
// Note: adler32 takes 12% for level 0 and 2% for level 6.
|
2
|
+
// It doesn't worth to make additional optimizationa as in original.
|
3
|
+
// Small size is preferable.
|
4
|
+
|
5
|
+
export default function adler32(adler, buf, len, pos) {
|
6
|
+
var s1 = (adler & 0xffff) |0,
|
7
|
+
s2 = ((adler >>> 16) & 0xffff) |0,
|
8
|
+
n = 0;
|
9
|
+
|
10
|
+
while (len !== 0) {
|
11
|
+
// Set limit ~ twice less than 5552, to keep
|
12
|
+
// s2 in 31-bits, because we force signed ints.
|
13
|
+
// in other case %= will fail.
|
14
|
+
n = len > 2000 ? 2000 : len;
|
15
|
+
len -= n;
|
16
|
+
|
17
|
+
do {
|
18
|
+
s1 = (s1 + buf[pos++]) |0;
|
19
|
+
s2 = (s2 + s1) |0;
|
20
|
+
} while (--n);
|
21
|
+
|
22
|
+
s1 %= 65521;
|
23
|
+
s2 %= 65521;
|
24
|
+
}
|
25
|
+
|
26
|
+
return (s1 | (s2 << 16)) |0;
|
27
|
+
}
|
@@ -0,0 +1,47 @@
|
|
1
|
+
export default {
|
2
|
+
|
3
|
+
/* Allowed flush values; see deflate() and inflate() below for details */
|
4
|
+
Z_NO_FLUSH: 0,
|
5
|
+
Z_PARTIAL_FLUSH: 1,
|
6
|
+
Z_SYNC_FLUSH: 2,
|
7
|
+
Z_FULL_FLUSH: 3,
|
8
|
+
Z_FINISH: 4,
|
9
|
+
Z_BLOCK: 5,
|
10
|
+
Z_TREES: 6,
|
11
|
+
|
12
|
+
/* Return codes for the compression/decompression functions. Negative values
|
13
|
+
* are errors, positive values are used for special but normal events.
|
14
|
+
*/
|
15
|
+
Z_OK: 0,
|
16
|
+
Z_STREAM_END: 1,
|
17
|
+
Z_NEED_DICT: 2,
|
18
|
+
Z_ERRNO: -1,
|
19
|
+
Z_STREAM_ERROR: -2,
|
20
|
+
Z_DATA_ERROR: -3,
|
21
|
+
//Z_MEM_ERROR: -4,
|
22
|
+
Z_BUF_ERROR: -5,
|
23
|
+
//Z_VERSION_ERROR: -6,
|
24
|
+
|
25
|
+
/* compression levels */
|
26
|
+
Z_NO_COMPRESSION: 0,
|
27
|
+
Z_BEST_SPEED: 1,
|
28
|
+
Z_BEST_COMPRESSION: 9,
|
29
|
+
Z_DEFAULT_COMPRESSION: -1,
|
30
|
+
|
31
|
+
|
32
|
+
Z_FILTERED: 1,
|
33
|
+
Z_HUFFMAN_ONLY: 2,
|
34
|
+
Z_RLE: 3,
|
35
|
+
Z_FIXED: 4,
|
36
|
+
Z_DEFAULT_STRATEGY: 0,
|
37
|
+
|
38
|
+
/* Possible values of the data_type field (though see inflate()) */
|
39
|
+
Z_BINARY: 0,
|
40
|
+
Z_TEXT: 1,
|
41
|
+
//Z_ASCII: 1, // = Z_TEXT (deprecated)
|
42
|
+
Z_UNKNOWN: 2,
|
43
|
+
|
44
|
+
/* The deflate compression method */
|
45
|
+
Z_DEFLATED: 8
|
46
|
+
//Z_NULL: null // Use -1 or null inline, depending on var type
|
47
|
+
};
|
@@ -0,0 +1,36 @@
|
|
1
|
+
// Note: we can't get significant speed boost here.
|
2
|
+
// So write code to minimize size - no pregenerated tables
|
3
|
+
// and array tools dependencies.
|
4
|
+
|
5
|
+
|
6
|
+
// Use ordinary array, since untyped makes no boost here
|
7
|
+
export default function makeTable() {
|
8
|
+
var c, table = [];
|
9
|
+
|
10
|
+
for (var n = 0; n < 256; n++) {
|
11
|
+
c = n;
|
12
|
+
for (var k = 0; k < 8; k++) {
|
13
|
+
c = ((c & 1) ? (0xEDB88320 ^ (c >>> 1)) : (c >>> 1));
|
14
|
+
}
|
15
|
+
table[n] = c;
|
16
|
+
}
|
17
|
+
|
18
|
+
return table;
|
19
|
+
}
|
20
|
+
|
21
|
+
// Create table on load. Just 255 signed longs. Not a problem.
|
22
|
+
var crcTable = makeTable();
|
23
|
+
|
24
|
+
|
25
|
+
function crc32(crc, buf, len, pos) {
|
26
|
+
var t = crcTable,
|
27
|
+
end = pos + len;
|
28
|
+
|
29
|
+
crc ^= -1;
|
30
|
+
|
31
|
+
for (var i = pos; i < end; i++) {
|
32
|
+
crc = (crc >>> 8) ^ t[(crc ^ buf[i]) & 0xFF];
|
33
|
+
}
|
34
|
+
|
35
|
+
return (crc ^ (-1)); // >>> 0;
|
36
|
+
}
|