-
Notifications
You must be signed in to change notification settings - Fork 13
/
zlib_worker.js
34 lines (28 loc) · 1005 Bytes
/
zlib_worker.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
'use strict';
const zlib = require('zlib');
const ever = require('ever');
module.exports = function() {
ever(self).on('message', function(ev) {
const compressedArrayBuffer = ev.data.compressed;
const compressedArrayView = new Uint8Array(compressedArrayBuffer, ev.data.byteOffset, ev.data.byteLength);
const compressedBuffer = new Buffer(compressedArrayView);
const id = ev.data.id;
console.log('worker decomp start '+id+' len'+compressedBuffer.length);
zlib.inflate(compressedBuffer, function(err, decompressed) {
console.log('worker err'+ err);
if(err) {
self.postMessage({
id:id,
compressed:compressedArrayBuffer,
err:err.toString()}, // toString() to make cloneable
[compressedArrayBuffer]);
return;
}
const decompressedBuffer = decompressed.buffer;
self.postMessage({
id:id,
decompressed:decompressedBuffer},
[decompressedBuffer]);
});
});
};