Skip to content

Commit

Permalink
Bugfix inflate.js
Browse files Browse the repository at this point in the history
  • Loading branch information
Avaer Kazmer committed Nov 5, 2019
1 parent 80e3922 commit 27e72cf
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 5 deletions.
2 changes: 1 addition & 1 deletion inflate.js
Original file line number Diff line number Diff line change
Expand Up @@ -2152,4 +2152,4 @@
// 'zip' may not be defined in z-worker and some tests
var env = global.zip || global;
env.Inflater = env._jzlib_Inflater = Inflater;
})(this);
})(self);
12 changes: 8 additions & 4 deletions zip.js
Original file line number Diff line number Diff line change
Expand Up @@ -892,14 +892,18 @@ const basePath = import.meta.url.replace(/[^\/]*$/, '');
scripts = DEFAULT_WORKER_SCRIPTS[type].slice(0);
scripts[0] = (obj.zip.workerScriptsPath || '') + scripts[0];
}
const _readScript = async (src, text) => {
const _readBlob = async (src, text) => {
const res = await fetch(src);
return await (text ? res.text() : res.blob());
return await res.blob();
};
var worker = new Worker(URL.createObjectURL(await _readScript(scripts[0], false)));
const _readText = async (src, text) => {
const res = await fetch(src);
return await res.text();
};
var worker = new Worker(URL.createObjectURL(await _readBlob(scripts[0])));
// record total consumed time by inflater/deflater/crc32 in this worker
worker.codecTime = worker.crcTime = 0;
worker.postMessage({ type: 'importScripts', scripts: await Promise.all(scripts.slice(1).map(src => _readScript(src, true))) });
worker.postMessage({ type: 'importScripts', scripts: await Promise.all(scripts.slice(1).map(src => _readText(src))) });
worker.addEventListener('message', onmessage);
function onmessage(ev) {
var msg = ev.data;
Expand Down

0 comments on commit 27e72cf

Please sign in to comment.