1.

Why Zlib is used in Node.js?

Answer»

The Zlib module provides a way to zip and unzip files. Zlib is a Cross-stage data compression library. It was composed by Jean-loupGailly and Mark Adler. In Node js, you can Zlib for Threadpool, HTTP solicitations, and reactions pressure and Memory Usage Tuning. So as to utilize zlib in node js, you have to introduce HUB zlib bundle. After ESTABLISHMENT, below is the test code to utilize Zlib. 

var Buffer = require('buffer').Buffer;  var zlib = require('zlib');  var input = NEW Buffer('lorem ipsum dolor sit amet');  var compressed = zlib.DEFLATE(input);  var output = zlib.inflate(compressed);

Following are a few important Zlib properties and Methods:- 

MethodDescription 

  • constantsReturns an object containing Zlib constants 
  • createDeflate()Creates a Deflate object 
  • createDeflateRaw()Creates a DeflateRaw object 
  • createGunzip()Creates a Gunzip object 
  • createGzip()Creates a Gzip object 
  • unzip()Decompress a string or buffer, using Unzip 
  • unzipSync()Decompress a string or buffer, synchronously, using Unzip 
  • deflate()Compress a string or buffer, using Deflate 
  • gzip()Compress a string or buffer, using Gzip 
  • gzipSync()Compress a string or buffer, synchronously, using Gzip 
  • inflate()Decompress a string or buffer, using Inflate 
  • inflateSync()Decompress a string or buffer, synchronously, using Inflate 


Discussion

No Comment Found