Below is the Python code snippet I am working with:
import zlib
raw = bytes.fromhex("789C34C9410AC2301005D0BBFC752289A88BB94A53CAD8061B48D3329D2A1A7277DDB87BF02A14548E9C0DF63FD60DE49DC104AA98238BDE23EB908A467972065DFCF9FAFB4185C708EAD0053C58E38BDF7693C92E9C8A9DFDE716606AC0924659F7007227D77AF4AD7D010000FFFF")
buffer = bytearray()
inflator = zlib.decompressobj()
buffer.extend(raw)
msg = inflator.decompress(buffer)
print("[buffer] ", msg)
This successfully decompresses the data in Python.
Next, here is a similar code snippet in JavaScript (TypeScript):
import zlib from "zlib"
const raw = "789C34C9410AC2301005D0BBFC752289A88BB94A53CAD8061B48D3329D2A1A7277DDB87BF02A14548E9C0DF63FD60DE49DC104AA98238BDE23EB908A467972065DFCF9FAFB4185C708EAD0053C58E38BDF7693C92E9C8A9DFDE716606AC0924659F7007227D77AF4AD7D010000FFFF";
let msg;
let buffer;
buffer = Buffer.from(raw, "hex");
msg = zlib.inflateSync(buffer);
console.log("[buffer] " + msg.toString("utf-8"));
In this JavaScript code, an error occurs as follows:
Error: unexpected end of file
at Zlib.zlibOnError [as onerror] (node:zlib:190:17)
at processChunkSync (node:zlib:456:12)
at zlibBufferSync (node:zlib:178:12)
at Object.syncBufferWrapper [as inflateSync] (node:zlib:791:14)
at Object.
at Module._compile (node:internal/modules/cjs/loader:1101:14)
at Module.m._compile (C:\Users\User\AppData\Roaming\npm\node_modules\ts-node\src\index.ts:1455:23)
at Module._extensions..js (node:internal/modules/cjs/loader:1153:10)
at Object.require.extensions. [as .ts]
at Module.load (node:internal/modules/cjs/loader:981:32) {
errno: -5,
code: 'Z_BUF_ERROR'
}
We see that there is an error in the JavaScript code but not the Python one. Let's investigate why this difference exists.