Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What's the encoding should I use to "gzuncompress()" in node.js?

I'm converting my code from PHP to node.js, and I need to convert a part of my code where there's the gzuncompress() function.

For that I'm using zlib.inflateSync. But I don't know which encoding I should use to create the buffer and so to have the same result of php

Here's what I do with php to decompress a string:

gzuncompress(substr($this->raw, 8))

and here's what I've tried in node.js

zlib.inflateSync(new Buffer(this.raw.substr(8), "encoding"))

So what encoding should I use to make zlib.inflateSync returns the same data as gzuncompress ?

like image 344
DonkeyKong245 Avatar asked Dec 20 '25 17:12

DonkeyKong245


1 Answers

I am not sure about what would be exact encoding here however this repo has some PHP translations for node.js (https://github.com/gamalielmendez/node-fpdf/blob/master/src/PHP_CoreFunctions.js). According to this repo, the following could work:

const gzuncompress = (data) => {
    const chunk = (!Buffer.isBuffer(data)) ? Buffer.from(data, 'binary') : data
    const Z1 = zlib.inflateSync(chunk)
    return Z1.toString('binary')//'ascii'
}
like image 75
manishg Avatar answered Dec 23 '25 06:12

manishg



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!