Skip to content

Commit

Permalink
Fix Deno
Browse files Browse the repository at this point in the history
  • Loading branch information
101arrowz committed Mar 21, 2021
1 parent e3f587a commit 7261536
Show file tree
Hide file tree
Showing 4 changed files with 18 additions and 4 deletions.
10 changes: 10 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,16 @@ You may also want to specify the version, e.g. with [email protected]
</script>
```

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
Expand Down
4 changes: 2 additions & 2 deletions docs/classes/asyncgunzip.md
Original file line number Diff line number Diff line change
Expand Up @@ -25,15 +25,15 @@ 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

#### Parameters:

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)

Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -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",
Expand Down
6 changes: 5 additions & 1 deletion src/worker.ts
Original file line number Diff line number Diff line change
@@ -1,15 +1,19 @@
const ch2: Record<string, string> = {};

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 <T>(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);
Expand Down

0 comments on commit 7261536

Please sign in to comment.