han0idx han0idx - 1 year ago 101
Node.js Question

Deflate Buffer using no compression mode

Anyone know how to deflate a buffer using

? The problem is that I don't know where and how to use the
option. Here is my code:

var fs = require('fs');
var path = require('path');
const zlib = require('zlib');
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!");

Answer Source

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) {
 // ...
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download