You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

75 lines
1.8 KiB

3 months ago
  1. # gzip-size [![Build Status](https://travis-ci.com/sindresorhus/gzip-size.svg?branch=master)](https://travis-ci.com/github/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<number>` with 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<number>` with 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. ---
  37. <div align="center">
  38. <b>
  39. <a href="https://tidelift.com/subscription/pkg/npm-gzip-size?utm_source=npm-gzip-size&utm_medium=referral&utm_campaign=readme">Get professional support for this package with a Tidelift subscription</a>
  40. </b>
  41. <br>
  42. <sub>
  43. Tidelift helps make open source sustainable for maintainers while giving companies<br>assurances about security, maintenance, and licensing for their dependencies.
  44. </sub>
  45. </div>