making zlib usable in browsers

pull/431/head
El RIDO 2019-05-11 10:38:14 +02:00
parent 20befe4bd6
commit 5b3286df4d
No known key found for this signature in database
GPG Key ID: 0F5C940A6BD81F92
2 changed files with 139 additions and 137 deletions

View File

@ -11,7 +11,7 @@ global.WebCrypto = require('node-webcrypto-ossl');
// application libraries to test
global.$ = global.jQuery = require('./jquery-3.3.1');
global.RawDeflate = require('./rawinflate-0.3').RawDeflate;
require('./zlib-1.2.11');
global.zlib = require('./zlib-1.2.11').zlib;
require('./prettify');
global.prettyPrint = window.PR.prettyPrint;
global.prettyPrintOne = window.PR.prettyPrintOne;

View File

@ -1,5 +1,6 @@
'use strict';
(function() {
let ret;
async function initialize() {
@ -23,14 +24,15 @@ async function initialize() {
_grow: () => { },
};
let ins;
let buff;
if (typeof fetch === 'undefined') {
const buff = fs.readFileSync('zlib-1.2.11.wasm');
const module = await WebAssembly.compile(buff);
ins = await WebAssembly.instantiate(module, { env });
buff = fs.readFileSync('zlib-1.2.11.wasm');
} 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 dstPtr = ins.exports._malloc(CHUNK_SIZE);
@ -140,5 +142,5 @@ async function initialize() {
return ret;
}
global.zlib = initialize();
this.zlib = initialize();
}).call(this);