Arjun Barrett hace 4 años
padre
commit
7261536e5a
Se han modificado 4 ficheros con 18 adiciones y 4 borrados
  1. 10 0
      README.md
  2. 2 2
      docs/classes/asyncgunzip.md
  3. 1 1
      package.json
  4. 5 1
      src/worker.ts

+ 10 - 0
README.md

@@ -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

+ 2 - 2
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)
 

+ 1 - 1
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",

+ 5 - 1
src/worker.ts

@@ -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);