making zlib usable in browsers
This commit is contained in:
parent
20befe4bd6
commit
5b3286df4d
2 changed files with 139 additions and 137 deletions
|
@ -11,7 +11,7 @@ global.WebCrypto = require('node-webcrypto-ossl');
|
||||||
// application libraries to test
|
// application libraries to test
|
||||||
global.$ = global.jQuery = require('./jquery-3.3.1');
|
global.$ = global.jQuery = require('./jquery-3.3.1');
|
||||||
global.RawDeflate = require('./rawinflate-0.3').RawDeflate;
|
global.RawDeflate = require('./rawinflate-0.3').RawDeflate;
|
||||||
require('./zlib-1.2.11');
|
global.zlib = require('./zlib-1.2.11').zlib;
|
||||||
require('./prettify');
|
require('./prettify');
|
||||||
global.prettyPrint = window.PR.prettyPrint;
|
global.prettyPrint = window.PR.prettyPrint;
|
||||||
global.prettyPrintOne = window.PR.prettyPrintOne;
|
global.prettyPrintOne = window.PR.prettyPrintOne;
|
||||||
|
|
|
@ -1,8 +1,9 @@
|
||||||
'use strict';
|
'use strict';
|
||||||
|
|
||||||
let ret;
|
(function() {
|
||||||
|
let ret;
|
||||||
|
|
||||||
async function initialize() {
|
async function initialize() {
|
||||||
if (ret) return ret;
|
if (ret) return ret;
|
||||||
|
|
||||||
const COMPRESSION_LEVEL = 7;
|
const COMPRESSION_LEVEL = 7;
|
||||||
|
@ -23,14 +24,15 @@ async function initialize() {
|
||||||
_grow: () => { },
|
_grow: () => { },
|
||||||
};
|
};
|
||||||
|
|
||||||
let ins;
|
let buff;
|
||||||
if (typeof fetch === 'undefined') {
|
if (typeof fetch === 'undefined') {
|
||||||
const buff = fs.readFileSync('zlib-1.2.11.wasm');
|
buff = fs.readFileSync('zlib-1.2.11.wasm');
|
||||||
const module = await WebAssembly.compile(buff);
|
|
||||||
ins = await WebAssembly.instantiate(module, { env });
|
|
||||||
} else {
|
} else {
|
||||||
ins = await WebAssembly.instantiateStreaming(fetch('zlib-1.2.11.wasm'));
|
const resp = await fetch('js/zlib-1.2.11.wasm');
|
||||||
|
buff = await resp.arrayBuffer();
|
||||||
}
|
}
|
||||||
|
const module = await WebAssembly.compile(buff);
|
||||||
|
const ins = await WebAssembly.instantiate(module, { env });
|
||||||
|
|
||||||
const srcPtr = ins.exports._malloc(CHUNK_SIZE);
|
const srcPtr = ins.exports._malloc(CHUNK_SIZE);
|
||||||
const dstPtr = ins.exports._malloc(CHUNK_SIZE);
|
const dstPtr = ins.exports._malloc(CHUNK_SIZE);
|
||||||
|
@ -139,6 +141,6 @@ async function initialize() {
|
||||||
}
|
}
|
||||||
|
|
||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
this.zlib = initialize();
|
||||||
global.zlib = initialize();
|
}).call(this);
|
||||||
|
|
Loading…
Reference in a new issue