From 7261536e5a83fbf3a9b9426ba1d0b52088f10b17 Mon Sep 17 00:00:00 2001 From: Arjun Barrett Date: Sat, 20 Mar 2021 19:44:10 -0700 Subject: [PATCH] Fix Deno --- README.md | 10 ++++++++++ docs/classes/asyncgunzip.md | 4 ++-- package.json | 2 +- src/worker.ts | 6 +++++- 4 files changed, 18 insertions(+), 4 deletions(-) diff --git a/README.md b/README.md index 9d373a1..5ae81d2 100644 --- a/README.md +++ b/README.md @@ -71,6 +71,16 @@ You may also want to specify the version, e.g. with fflate@0.4.8 ``` +If you are using Deno: +```js +// Don't use the ?dts Skypack flag; it isn't necessary for Deno support +// The @deno-types comment adds TypeScript typings + +// @deno-types="https://cdn.skypack.dev/fflate/lib/index.d.ts" +import * as fflate from 'https://cdn.skypack.dev/fflate?min'; +``` + + If your environment doesn't support bundling: ```js // Again, try to import just what you need diff --git a/docs/classes/asyncgunzip.md b/docs/classes/asyncgunzip.md index 072c95f..14c48ce 100644 --- a/docs/classes/asyncgunzip.md +++ b/docs/classes/asyncgunzip.md @@ -25,7 +25,7 @@ Asynchronous streaming GZIP decompression ### constructor -\+ **new AsyncGunzip**(`cb`: [AsyncFlateStreamHandler](../README.md#asyncflatestreamhandler)): [AsyncGunzip](asyncgunzip.md) +\+ **new AsyncGunzip**(`cb?`: [AsyncFlateStreamHandler](../README.md#asyncflatestreamhandler)): [AsyncGunzip](asyncgunzip.md) Creates an asynchronous GUNZIP stream @@ -33,7 +33,7 @@ Creates an asynchronous GUNZIP stream Name | Type | Description | ------ | ------ | ------ | -`cb` | [AsyncFlateStreamHandler](../README.md#asyncflatestreamhandler) | The callback to call whenever data is deflated | +`cb?` | [AsyncFlateStreamHandler](../README.md#asyncflatestreamhandler) | The callback to call whenever data is deflated | **Returns:** [AsyncGunzip](asyncgunzip.md) diff --git a/package.json b/package.json index b3287e9..e946807 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "fflate", - "version": "0.6.8", + "version": "0.6.9", "description": "High performance (de)compression in an 8kB package", "main": "./lib/index.cjs", "module": "./esm/browser.js", diff --git a/src/worker.ts b/src/worker.ts index 0f56b15..6d0988f 100644 --- a/src/worker.ts +++ b/src/worker.ts @@ -1,15 +1,19 @@ 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 = new Worker(ch2[id] ||= durl(c)); + const w = cwk(ch2[id] ||= durl(c)); w.onerror = e => cb(e.error, null); w.onmessage = e => cb(null, e.data); w.postMessage(msg, transfer);