I have some API which need the sign with encrypted by gzencode function in php, now I need to use nodejs to make a test tools for testing these API.
I've tried pako
and zlib
module in nodejs, however, the compress result was always different from php, so I want to know how can I make the same compress result in nodejs like gzencode in php7 ?
const pako = require('pako');
const zlib = require('zlib');
const crypto = require('crypto');
const input = '1234';
zlib.gzip(input, (err, buffer) => {
if (!err) {
console.log("--------zlib result---------");
console.log(buffer.toString());
console.log("");
console.log("length: " + buffer.toString().length);
console.log("md5: " + crypto.createHash('md5').update(buffer.toString()).digest("hex"));
}
});
var result = pako.gzip(input, { to: 'string' });
console.log("--------pako result---------");
console.log(result);
console.log("");
console.log("length: " + result.length);
console.log("md5: " + crypto.createHash('md5').update(result).digest("hex"));
$str = gzencode('1234');
var_dump($str);
var_dump(strlen($str));
var_dump(md5($str));
nodejs result
pako result
3426 £àã
length: 24
md5: 45461056d1301798aae739d467b1811b
zlib result
3426 ���
length: 23
md5: ea90ab1d16e5596020fb313119879e26<br/>
php result
string(24) "3426"
int(24)
string(32) "cbe26958c184e607833efbf9b63516fb"