101arrowz 3 tahun lalu
induk
melakukan
9110b06af7
5 mengubah file dengan 15 tambahan dan 14 penghapusan
  1. 4 0
      CHANGELOG.md
  2. 3 3
      docs/README.md
  3. 1 1
      package.json
  4. 1 1
      scripts/buildUMD.ts
  5. 6 9
      src/index.ts

+ 4 - 0
CHANGELOG.md

@@ -1,3 +1,7 @@
+## 0.7.2
+- Fixed TypeScript typing for errors when using `strictNullChecks`
+- Fixed failure to compress files above 64kB with `{ level: 0 }`
+- Fixed AMD module definition in UMD build
 ## 0.7.1
 - Removed requirement for `setTimeout`
 - Added support for unzip file filters (thanks to [@manucorporat](https://github.com/manucorporat): #67)

+ 3 - 3
docs/README.md

@@ -99,7 +99,7 @@
 
 ### AsyncFlateStreamHandler
 
-Ƭ  **AsyncFlateStreamHandler**: (err: [FlateError](interfaces/flateerror.md),data: Uint8Array,final: boolean) => void
+Ƭ  **AsyncFlateStreamHandler**: (err: [FlateError](interfaces/flateerror.md) \| null,data: Uint8Array,final: boolean) => void
 
 Handler for asynchronous data (de)compression streams
 
@@ -121,7 +121,7 @@ ___
 
 ### FlateCallback
 
-Ƭ  **FlateCallback**: (err: [FlateError](interfaces/flateerror.md),data: Uint8Array) => void
+Ƭ  **FlateCallback**: (err: [FlateError](interfaces/flateerror.md) \| null,data: Uint8Array) => void
 
 Callback for asynchronous (de)compression methods
 
@@ -157,7 +157,7 @@ ___
 
 ### UnzipCallback
 
-Ƭ  **UnzipCallback**: (err: [FlateError](interfaces/flateerror.md),data: [Unzipped](interfaces/unzipped.md)) => void
+Ƭ  **UnzipCallback**: (err: [FlateError](interfaces/flateerror.md) \| null,data: [Unzipped](interfaces/unzipped.md)) => void
 
 Callback for asynchronous ZIP decompression
 

+ 1 - 1
package.json

@@ -1,6 +1,6 @@
 {
   "name": "fflate",
-  "version": "0.7.1",
+  "version": "0.7.2",
   "description": "High performance (de)compression in an 8kB package",
   "main": "./lib/index.cjs",
   "module": "./esm/browser.js",

+ 1 - 1
scripts/buildUMD.ts

@@ -29,7 +29,7 @@ minify(src, opts).then(async out => {
     /exports.__esModule=!0;/,
     ''
   );
-  const res = "!function(f){typeof module!='undefined'&&typeof exports=='object'?module.exports=f():typeof define!='undefined'&&define.amd?define(['fflate',f]):(typeof self!='undefined'?self:this).fflate=f()}(function(){var _e={};" +
+  const res = "!function(f){typeof module!='undefined'&&typeof exports=='object'?module.exports=f():typeof define!='undefined'&&define.amd?define(f):(typeof self!='undefined'?self:this).fflate=f()}(function(){var _e={};" +
     out.code!.replace(/exports\.(.*) = void 0;\n/, '').replace(/exports\./g, '_e.').replace(/require\("\.\/node-worker\.cjs"\)/,
     "(typeof module!='undefined'&&typeof exports=='object'?function(_f){" + nodeWkrOut + 'return _f}:function(_f){' + wkrOut + 'return _f})({})'
   ) + 'return _e})';

+ 6 - 9
src/index.ts

@@ -624,14 +624,11 @@ const dflt = (dat: Uint8Array, lvl: number, plvl: number, pre: number, post: num
     for (let i = 0; i <= s; i += 65535) {
       // end
       const e = i + 65535;
-      if (e < s) {
-        // write full block
-        pos = wfblk(w, pos, dat.subarray(i, e));
-      } else {
+      if (e >= s) {
         // write final block
-        w[i] = lst;
-        pos = wfblk(w, pos, dat.subarray(i, s));
+        w[pos >> 3] = lst;
       }
+      pos = wfblk(w, pos + 1, dat.subarray(i, e));
     }
   } else {
     const opt = deo[lvl - 1];
@@ -844,14 +841,14 @@ export type FlateStreamHandler = (data: Uint8Array, final: boolean) => void;
  * @param data The data output from the stream processor
  * @param final Whether this is the final block
  */
-export type AsyncFlateStreamHandler = (err: FlateError, data: Uint8Array, final: boolean) => void;
+export type AsyncFlateStreamHandler = (err: FlateError | null, data: Uint8Array, final: boolean) => void;
 
 /**
  * Callback for asynchronous (de)compression methods
  * @param err Any error that occurred
  * @param data The resulting data. Only present if `err` is null
  */
-export type FlateCallback = (err: FlateError, data: Uint8Array) => void;
+export type FlateCallback = (err: FlateError | null, data: Uint8Array) => void;
 
 // async callback-based compression
 interface AsyncOptions {
@@ -2087,7 +2084,7 @@ export type StringStreamHandler = (data: string, final: boolean) => void;
  * @param err Any error that occurred
  * @param data The decompressed ZIP archive
  */
-export type UnzipCallback = (err: FlateError, data: Unzipped) => void;
+export type UnzipCallback = (err: FlateError | null, data: Unzipped) => void;
 
 /**
  * Handler for streaming ZIP decompression