The plaintext response from zlib.gzipSync
gives different data when running the below code snippet on MacOS and Ubuntu.
const zlib = require('zlib');
let hash = zlib.gzipSync(JSON.stringify({ "foo": "bar" })).toString('base64');
console.log(hash);
NodeJS version: v14.19.1
H4sIAAAAAAAAE6tWSsvPV7JSSkosUqoFAO/1K/4NAAAA
-> Mac Output
H4sIAAAAAAAAA6tWSsvPV7JSSkosUqoFAO/1K/4NAAAA
-> Ubuntu Output
Ideally, shouldn't this hash be the same across platforms?
It's not a "hash", and no, it's perfectly fine to be different across platforms. In this case, the OS byte differs in the gzip headers.
You can expect compressed data streams to differ in other ways as well. Sometimes the modified timestamp is set in the gzip header. Then even on the same machine you can get different streams. For larger compressed data, different compression code, a different version of the same code, or different compression levels will give different data.
All that matters is that the original data is recovered exactly when decompressing.