The Node.js Zlib module is used to provide compression and decompression (zip and unzip) functionalities. It is implemented using Gzip and deflate/inflate.
The zlib module can be accessed using:
Compressing and decompressing a file can be done by piping the source stream data into a destination stream through zlib stream.
Node.js ZLIB Example: Compress File
Let's see a simple example of Node.js ZLIB module to compress a file "input.txt" into "input.txt.gz".
File: zlib_example1.js
We have a text file named "input.txt" on the desktop.
Open Node.js command prompt and run the following code:
You can see that it will produce a compressed file named "input.txt.gz" on the desktop.
Node.js ZLIB Example: Decompress File
Let's see a simple example of Node.js ZLIB module to decompress a file "input.txt.gz" into "input2.txt".
File: zlib_example2.js
Now you will see that same code of "input.txt" is available into "input2.txt" file.
0 comments:
Post a Comment
Note: only a member of this blog may post a comment.