From 3a1a6a94d26a96ee5d02c23845a7511813992ee5 Mon Sep 17 00:00:00 2001 From: n1073645 Date: Mon, 16 Dec 2019 17:05:06 +0000 Subject: [PATCH] Sets the gzip comment bitfield --- src/core/operations/Gunzip.mjs | 10 ++++++---- src/core/operations/Gzip.mjs | 16 ++++++++++------ 2 files changed, 16 insertions(+), 10 deletions(-) diff --git a/src/core/operations/Gunzip.mjs b/src/core/operations/Gunzip.mjs index 07b1d6c2..ace795be 100644 --- a/src/core/operations/Gunzip.mjs +++ b/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; } } diff --git a/src/core/operations/Gzip.mjs b/src/core/operations/Gzip.mjs index 5f9fa474..b0ed9b53 100644 --- a/src/core/operations/Gzip.mjs +++ b/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; } }