Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 1 addition & 3 deletions src/core/operations/Gzip.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -74,13 +74,11 @@ class Gzip extends Operation {
}
if (comment.length) {
options.flags.comment = true;
options.flags.fcomment = true;
options.comment = comment;
}
const gzipObj = new Zlib.Gzip(new Uint8Array(input), options);
const compressed = new Uint8Array(gzipObj.compress());
if (options.flags.comment && !(compressed[3] & 0x10)) {
compressed[3] |= 0x10;
}
return compressed.buffer;
}

Expand Down
60 changes: 60 additions & 0 deletions tests/operations/tests/Gzip.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -86,4 +86,64 @@ TestRegister.addTests([
}
]
},
{
name: "Gzip: Comment with checksum round-trips through Gunzip",
input: "hello hello hello",
expectedOutput: "hello hello hello",
recipeConfig: [
{
op: "Gzip",
args: ["Dynamic Huffman Coding", "", "test", true]
},
{
op: "Gunzip",
args: []
}
]
},
{
name: "Gzip: Filename and comment with checksum round-trips through Gunzip",
input: "The quick brown fox jumped over the slow dog",
expectedOutput: "The quick brown fox jumped over the slow dog",
recipeConfig: [
{
op: "Gzip",
args: ["Dynamic Huffman Coding", "file.txt", "a comment", true]
},
{
op: "Gunzip",
args: []
}
]
},
{
name: "Gzip: No comment, with checksum round-trips through Gunzip",
input: "The quick brown fox jumped over the slow dog",
expectedOutput: "The quick brown fox jumped over the slow dog",
recipeConfig: [
{
op: "Gzip",
args: ["Dynamic Huffman Coding", "", "", true]
},
{
op: "Gunzip",
args: []
}
]
},
{
name: "Gzip: No options round-trips through Gunzip",
input: "The quick brown fox jumped over the slow dog",
expectedOutput: "The quick brown fox jumped over the slow dog",
recipeConfig: [
{
op: "Gzip",
args: ["Dynamic Huffman Coding", "", "", false]
},
{
op: "Gunzip",
args: []
}
]
},
]);