dr.dimitru
dr.dimitru

Reputation: 2702

Node.js: zlib.gzipSync()

I have a few questions on zlib module, to be used with files under 40MB:

  1. What kind of options should be used in zlib.gzipSync() for fastest zipping (compression level does not matter)?
  2. Which default values is used, if options is not passed to the method?
  3. Is this method returns Buffer?
  4. What kind of extension and mime type should be used for final result?
  5. Update: How to pass a file name? (So after unzipping file has name and extension)

Asked because reference is not expressive.

Upvotes: 3

Views: 5724

Answers (2)

josh3736
josh3736

Reputation: 144912

The docs describe the options object used for every zlib call. They also point you to the zlib manual which describes those options in great detail.

The fastest level is 0, which means no compression. However, this would be silly, since you may as well skip gzipping altogether. 1 means "some compression with best speed."

That said, don't use gzipSync. We don't do things synchronously in node. If you're looking to write the compressed data to a file, do:

var compressor = zlib.createGzip({level: 1});
compressor.pipe(fs.createWriteStream('output.gz'));

compressor.end(inputData);

Upvotes: 0

Mark Adler
Mark Adler

Reputation: 112394

Yeah, not much to go on in that documentation.

I recommend that you look at the zlib manual (the zlib.h source file) for information on the noted parameters and operations.

The fastest compression would be level 1.

The default compression level is 6. Other defaults can be found in zlib.h.

There does not appear to be an interface to deflateSetHeader(), which would be required to insert a file name in a gzip header.

Upvotes: 1

Related Questions