-
Notifications
You must be signed in to change notification settings - Fork 349
Open
Description
RawDeflate with FIXED or NONE mode doesn't work well with an 0-byte input. (DYNAMIC looks working)
Using NONE produces 32768 0x00s, which results in an error when inflated.
Using FIXED produces 1-byte output 0x03, but it also results in an error when inflated.
Test code (tested on RunKit + npm: zlibjs with Node 16):
var rawdeflate = require("zlibjs/bin/rawdeflate.min.js");
var rawinflate = require("zlibjs/bin/rawinflate.min.js");
var inputArray = new Uint8Array([]);
console.log(inputArray);
var options = [
rawdeflate.Zlib.RawDeflate.CompressionType.NONE,
rawdeflate.Zlib.RawDeflate.CompressionType.FIXED,
rawdeflate.Zlib.RawDeflate.CompressionType.DYNAMIC
];
for (var i = 0; i < options.length; i++) {
console.log(options[i]);
try {
var option = {
compressionType: options[i]
};
var deflate = new rawdeflate.Zlib.RawDeflate(inputArray, option);
var compressed = deflate.compress();
console.log(compressed);
var inflate = new rawinflate.Zlib.RawInflate(compressed);
var inflated = inflate.decompress();
console.log(inflated);
} catch(e) {
console.log(e);
}
}Reffering rfc1951, I think NONE should produce [0x01, 0x00, 0x00, 0xff, 0xff] and FIXED should produce [0x03, 0x00]. Both of them can be inflated to a 0-byte result.
var rawinflate = require("zlibjs/bin/rawinflate.min.js");
var noneExpected = new Uint8Array([0x01, 0x00, 0x00, 0xff, 0xff]);
var fixedExpected = new Uint8Array([0x03, 0x00]);
var inflateNone = new rawinflate.Zlib.RawInflate(noneExpected);
console.log(inflateNone.decompress());
var inflateFixed = new rawinflate.Zlib.RawInflate(fixedExpected);
console.log(inflateFixed.decompress());Reactions are currently unavailable
Metadata
Metadata
Assignees
Labels
No labels