Search code examples
node.jscompressionbufferdeflate

Deflate Buffer using no compression mode


Anyone know how to deflate a buffer using zlib.Z_NO_COMPRESSION? The problem is that I don't know where and how to use the Z_NO_COMPRESSION option. Here is my code:

var fs = require('fs');
var path = require('path');
const zlib = require('zlib');
zlib.Z_NO_COMPRESSION
zlib.deflate(stateInputs, function(err, res) {
    var fileOutput = Buffer.concat([bHeader,res]);
    fs.writeFile("./out.dat", fileOutput, function(err) {
        if(err) return console.log(err);
            console.log("The file was saved!");
        }); 
}); 

Solution

  • You can pass an options object to deflate(). One of these options is level which is where you'd set the compression level:

    zlib.deflate(stateInputs, {
      level: zlib.Z_NO_COMPRESSION
    }, function(err, res) {
     // ...
    });