Tuesday, 11 April 2017

node.js zlib base64 not unzlib.

I want long string compress..

So i follow this site. (https://nodejs.org/api/zlib.html)

Make two file

First file is just buffer file like this.

<Buffer 78 9c bd 7d db 92 dc 36 b6 e5 af 54 64 84 63 5e d0 0c 5c 09 32 df 2c b9 dd 9e d3 47 73 14 96 4f fb 39 55 4a ab d2 ca 8b 26 2b cb 6e a9 a3 7f 6b 7e 60 .

And base64 file like this. TGYSfOxeClRdiN4iU69aHJKEeWSfs/NOlGiWyRhq+Xk/AWzTtwT2EpApW6tPkCqt23nrEL3rsnUKMMUVNqTBgh1

So..

My problem is base64 file decompress not working. and make it this problem.

{ Error: incorrect header check at Zlib._handle.onerror (zlib.js:370:17) errno: -3, code: 'Z_DATA_ERROR' }

And buffer file is very good work decompress.

**

I want know why base64 file not work decompress?

**

This is my code.

app.get('/result',function(req,res){
res.send('hello');
fs.readFile('deflateHerosbase64.txt.gz',(err,data)=>{
    const buffer = Buffer.from(data,'base64');
    zlib.unzip(buffer, (err, buffer) => {
    if (!err) {
        console.log(buffer.toString());
    } else {
        // handle error
        console.log(err);
    }
    });
})



via King in the world.

No comments:

Post a Comment