diff --git a/README.md b/README.md index 5ae81d2..5c2a946 100644 --- a/README.md +++ b/README.md @@ -357,7 +357,7 @@ unzipper.push(zipChunk2); unzipper.push(zipChunk3, true); ``` -As you may have guessed, there is an asynchronous version of every method as well. Unlike most libraries, this will cause the compression or decompression run in a separate thread entirely and automatically by using Web (or Node) Workers. This means that the processing will not block the main thread at all. +As you may have guessed, there is an asynchronous version of every method as well. Unlike most libraries, this will cause the compression or decompression run in a separate thread entirely and automatically by using Web (or Node) Workers (as of now, Deno is unsupported). This means that the processing will not block the main thread at all. Note that there is a significant initial overhead to using workers of about 70ms, so it's best to avoid the asynchronous API unless necessary. However, if you're compressing multiple large files at once, or the synchronous API causes the main thread to hang for too long, the callback APIs are an order of magnitude better. ```js diff --git a/src/worker.ts b/src/worker.ts index 6d0988f..cd850d5 100644 --- a/src/worker.ts +++ b/src/worker.ts @@ -1,19 +1,7 @@ const ch2: Record = {}; -let durl = (c: string) => URL.createObjectURL(new Blob([c], { type: 'text/javascript' })); -let cwk = (u: string) => new Worker(u); - -try { - URL.revokeObjectURL(durl('')); -} catch(e) { - // We're in Deno or a very old browser - durl = c => 'data:application/javascript;charset=UTF-8,' + encodeURI(c); - // If Deno, this is necessary; if not, this changes nothing - cwk = u => new Worker(u, { type: 'module' }); -} - export default (c: string, id: number, msg: unknown, transfer: ArrayBuffer[], cb: (err: Error, msg: T) => void) => { - const w = cwk(ch2[id] ||= durl(c)); + const w = new Worker(ch2[id] ||= URL.createObjectURL(new Blob([c], { type: 'text/javascript' }))); w.onerror = e => cb(e.error, null); w.onmessage = e => cb(null, e.data); w.postMessage(msg, transfer);