Compressing/Decompressing Streams
Compressing/decompressing streams using Zlib is slightly different from compressing/decompressing buffers. Instead, you use the pipe() function to pipe the data from one stream through the compression/decompression object into another stream. This can apply to compressing any Readable streams into Writable streams.
A good example of doing this is compressing the contents of a file by using fs.ReadStream and fs.WriteStream. The code in Listing 5.12 shows an example of compressing the contents of one file by using a zlib.Gzip() object and then decompressing it by using a zlib.Gunzip() object. Notice that there is a 5 second timeout delay before trying to decompress the file to allow the data to be flushed to disk. ...
Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Read now
Unlock full access