You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
const unzipped = zlib.gunzipSync(Buffer.from(zippedString, encoding)).toString(encoding); // Error due to toString('utf8')
console.log('Unzipped string:');
console.log(unzipped);
How often does it reproduce? Is there a required condition?
Everytime, just run the above code
What is the expected behavior?
To return the previously zipped string
What do you see instead?
zlib.js:424
throw error;
^
Error: incorrect header check
at Zlib.zlibOnError [as onerror] (zlib.js:170:17)
at processChunkSync (zlib.js:416:12)
at zlibBufferSync (zlib.js:156:12)
at Object.syncBufferWrapper [as gunzipSync] (zlib.js:755:14)
at Object. (HelloWorld.js:17:23)
at Module._compile (internal/modules/cjs/loader.js:959:30)
at Object.Module._extensions..js (internal/modules/cjs/loader.js:995:10)
at Module.load (internal/modules/cjs/loader.js:815:32)
at Function.Module._load (internal/modules/cjs/loader.js:727:14)
at Function.Module.runMain (internal/modules/cjs/loader.js:1047:10) {
errno: -3,
code: 'Z_DATA_ERROR'
Additional information
I verified this on my private laptop and work laptop, on
Converting binary data to UTF-8 mangles the resulting output. If you really need to store it as a string, use something that will keep the binary representation intact like 'base64' or 'hex'(or even 'latin1' which would have the least overhead storage-wise but is not really ideal).
Version
14.7.5
Platform
Linux dn 5.11.0-34-generic #36-Ubuntu SMP x86_64 GNU/Linux
Subsystem
No response
What steps will reproduce the bug?
/Example zlib.gzipSync().toString() causes an Error: incorrect header check./
const zlib = require("zlib");
const zipHell = 'hello';
const encoding = 'utf8';
const zippedString = zlib.gzipSync(zipHell).toString(encoding); // Wrong causes error later
console.log('Zipped:');
console.log(zippedString);
const zippedBuffer = zlib.gzipSync(zipHell); // Works as expected
const unzippedBuffer = zlib.gunzipSync(Buffer.from(zippedBuffer, encoding)).toString(encoding); // No error
console.log('Unzipped buffer:');
console.log(unzippedBuffer);
const unzipped = zlib.gunzipSync(Buffer.from(zippedString, encoding)).toString(encoding); // Error due to toString('utf8')
console.log('Unzipped string:');
console.log(unzipped);
How often does it reproduce? Is there a required condition?
Everytime, just run the above code
What is the expected behavior?
To return the previously zipped string
What do you see instead?
zlib.js:424
throw error;
^
Error: incorrect header check
at Zlib.zlibOnError [as onerror] (zlib.js:170:17)
at processChunkSync (zlib.js:416:12)
at zlibBufferSync (zlib.js:156:12)
at Object.syncBufferWrapper [as gunzipSync] (zlib.js:755:14)
at Object. (HelloWorld.js:17:23)
at Module._compile (internal/modules/cjs/loader.js:959:30)
at Object.Module._extensions..js (internal/modules/cjs/loader.js:995:10)
at Module.load (internal/modules/cjs/loader.js:815:32)
at Function.Module._load (internal/modules/cjs/loader.js:727:14)
at Function.Module.runMain (internal/modules/cjs/loader.js:1047:10) {
errno: -3,
code: 'Z_DATA_ERROR'
Additional information
I verified this on my private laptop and work laptop, on
https://onecompiler.com/nodejs/3xb2q52ja
you will see the same error.
The text was updated successfully, but these errors were encountered: