Explorar o código

Sets the gzip comment bitfield

n1073645 %!s(int64=5) %!d(string=hai) anos
pai
achega
3a1a6a94d2
Modificáronse 2 ficheiros con 16 adicións e 10 borrados
  1. 6 4
      src/core/operations/Gunzip.mjs
  2. 10 6
      src/core/operations/Gzip.mjs

+ 6 - 4
src/core/operations/Gunzip.mjs

@@ -5,9 +5,11 @@
  */
 
 import Operation from "../Operation.mjs";
-import zlibAndGzip from "zlibjs/bin/zlib_and_gzip.min.js";
+// import zlibAndGzip from "zlibjs/bin/zlib_and_gzip.min.js";
+import gunzip from "zlibjs/bin/gunzip.min.js";
 
-const Zlib = zlibAndGzip.Zlib;
+// const Zlib = zlibAndGzip.Zlib;
+const Zlib = gunzip.Zlib;
 
 /**
  * Gunzip operation
@@ -42,8 +44,8 @@ class Gunzip extends Operation {
      * @returns {File}
      */
     run(input, args) {
-        const gunzip = new Zlib.Gunzip(new Uint8Array(input));
-        return new Uint8Array(gunzip.decompress()).buffer;
+        const gzipObj = new Zlib.Gunzip(new Uint8Array(input));
+        return new Uint8Array(gzipObj.decompress()).buffer;
     }
 
 }

+ 10 - 6
src/core/operations/Gzip.mjs

@@ -6,9 +6,10 @@
 
 import Operation from "../Operation.mjs";
 import {COMPRESSION_TYPE, ZLIB_COMPRESSION_TYPE_LOOKUP} from "../lib/Zlib.mjs";
-import zlibAndGzip from "zlibjs/bin/zlib_and_gzip.min.js";
+// import zlibAndGzip from "zlibjs/bin/zlib_and_gzip.min.js";
+import gzip from "zlibjs/bin/gzip.min.js";
 
-const Zlib = zlibAndGzip.Zlib;
+const Zlib = gzip.Zlib;
 
 /**
  * Gzip operation
@@ -73,12 +74,15 @@ class Gzip extends Operation {
             options.filename = filename;
         }
         if (comment.length) {
-            options.flags.fcommenct = true;
+            options.flags.comment = true;
             options.comment = comment;
         }
-
-        const gzip = new Zlib.Gzip(new Uint8Array(input), options);
-        return new Uint8Array(gzip.compress()).buffer;
+        const gzipObj = new Zlib.Gzip(new Uint8Array(input), options);
+        const compressed = new Uint8Array(gzipObj.compress());
+        if (options.flags.comment) {
+            compressed[3] |= 0x10;
+        }
+        return compressed.buffer;
     }
 
 }