d6d0143534f5ffdbb8b794d86148d4a573c9f115b6c9798d0841d6b4044d15f4ba3d6627fdb081a39b7e91c17cf05015398b8013af0611b3293fa0a047f0ba 1.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172
  1. # gzip-size [![Build Status](https://travis-ci.org/sindresorhus/gzip-size.svg?branch=master)](https://travis-ci.org/sindresorhus/gzip-size)
  2. > Get the gzipped size of a string or buffer
  3. ## Install
  4. ```
  5. $ npm install gzip-size
  6. ```
  7. ## Usage
  8. ```js
  9. const gzipSize = require('gzip-size');
  10. const text = 'Lorem ipsum dolor sit amet, consectetuer adipiscing elit. Aenean commodo ligula eget dolor. Aenean massa. Cum sociis natoque penatibus et magnis dis parturient montes, nascetur ridiculus mus.';
  11. console.log(text.length);
  12. //=> 191
  13. console.log(gzipSize.sync(text));
  14. //=> 78
  15. ```
  16. ## API
  17. ### gzipSize(input, [options])
  18. Returns a `Promise` for the size.
  19. ### gzipSize.sync(input, [options])
  20. Returns the size.
  21. #### input
  22. Type: `string` `Buffer`
  23. #### options
  24. Type: `Object`
  25. Any [`zlib` option](https://nodejs.org/api/zlib.html#zlib_class_options).
  26. ### gzipSize.stream([options])
  27. Returns a [`stream.PassThrough`](https://nodejs.org/api/stream.html#stream_class_stream_passthrough). The stream emits a `gzip-size` event and has a `gzipSize` property.
  28. ### gzipSize.file(path, [options])
  29. Returns a `Promise` for the size of the file.
  30. #### path
  31. Type: `string`
  32. ### gzipSize.fileSync(path, [options])
  33. Returns the size of the file.
  34. ## Related
  35. - [gzip-size-cli](https://github.com/sindresorhus/gzip-size-cli) - CLI for this module
  36. ## License
  37. MIT © [Sindre Sorhus](https://sindresorhus.com)