| 1 | # gzip-size [](https://travis-ci.com/github/sindresorhus/gzip-size)
|
|---|
| 2 |
|
|---|
| 3 | > Get the gzipped size of a string or buffer
|
|---|
| 4 |
|
|---|
| 5 | ## Install
|
|---|
| 6 |
|
|---|
| 7 | ```
|
|---|
| 8 | $ npm install gzip-size
|
|---|
| 9 | ```
|
|---|
| 10 |
|
|---|
| 11 | ## Usage
|
|---|
| 12 |
|
|---|
| 13 | ```js
|
|---|
| 14 | const gzipSize = require('gzip-size');
|
|---|
| 15 |
|
|---|
| 16 | 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.';
|
|---|
| 17 |
|
|---|
| 18 | console.log(text.length);
|
|---|
| 19 | //=> 191
|
|---|
| 20 |
|
|---|
| 21 | console.log(gzipSize.sync(text));
|
|---|
| 22 | //=> 78
|
|---|
| 23 | ```
|
|---|
| 24 |
|
|---|
| 25 | ## API
|
|---|
| 26 |
|
|---|
| 27 | ### gzipSize(input, options?)
|
|---|
| 28 |
|
|---|
| 29 | Returns a `Promise<number>` with the size.
|
|---|
| 30 |
|
|---|
| 31 | ### gzipSize.sync(input, options?)
|
|---|
| 32 |
|
|---|
| 33 | Returns the size.
|
|---|
| 34 |
|
|---|
| 35 | #### input
|
|---|
| 36 |
|
|---|
| 37 | Type: `string | Buffer`
|
|---|
| 38 |
|
|---|
| 39 | #### options
|
|---|
| 40 |
|
|---|
| 41 | Type: `object`
|
|---|
| 42 |
|
|---|
| 43 | Any [`zlib` option](https://nodejs.org/api/zlib.html#zlib_class_options).
|
|---|
| 44 |
|
|---|
| 45 | ### gzipSize.stream(options?)
|
|---|
| 46 |
|
|---|
| 47 | 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.
|
|---|
| 48 |
|
|---|
| 49 | ### gzipSize.file(path, options?)
|
|---|
| 50 |
|
|---|
| 51 | Returns a `Promise<number>` with the size of the file.
|
|---|
| 52 |
|
|---|
| 53 | #### path
|
|---|
| 54 |
|
|---|
| 55 | Type: `string`
|
|---|
| 56 |
|
|---|
| 57 | ### gzipSize.fileSync(path, options?)
|
|---|
| 58 |
|
|---|
| 59 | Returns the size of the file.
|
|---|
| 60 |
|
|---|
| 61 | ## Related
|
|---|
| 62 |
|
|---|
| 63 | - [gzip-size-cli](https://github.com/sindresorhus/gzip-size-cli) - CLI for this module
|
|---|
| 64 |
|
|---|
| 65 | ---
|
|---|
| 66 |
|
|---|
| 67 | <div align="center">
|
|---|
| 68 | <b>
|
|---|
| 69 | <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>
|
|---|
| 70 | </b>
|
|---|
| 71 | <br>
|
|---|
| 72 | <sub>
|
|---|
| 73 | Tidelift helps make open source sustainable for maintainers while giving companies<br>assurances about security, maintenance, and licensing for their dependencies.
|
|---|
| 74 | </sub>
|
|---|
| 75 | </div>
|
|---|