# gzip-size

> Get the gzipped size of a string or buffer

Latest version **7.0.0** (published 2021-11-23) · MIT license · 0 weekly downloads

## Install

```sh
npm install gzip-size
pnpm add gzip-size
yarn add gzip-size
bun add gzip-size
```

## Health

**Score 45/100 (D)** — status: abandoned.

Positive: has types; esm support; no vulnerabilities; high maintenance score; high quality score.

Warnings: low downloads.

Negative: abandoned.

## Facts

| | |
|---|---|
| Version | 7.0.0 |
| Published | 2021-11-23 |
| First published | 2014-02-28 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | bundled |
| Module format | ESM |
| Node | ^12.20.0 \|\| ^14.13.1 \|\| >=16.0.0 |
| Dependencies | 1 |
| Unpacked size | 8.1 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| GitHub stars | 173 |
| Author | Sindre Sorhus |
| Maintainers | sindresorhus |
| Keywords | app, tool, zlib, gzip, compressed, size, string, buffer |

## Links

- npm: https://www.npmjs.com/package/gzip-size
- Repository: https://github.com/sindresorhus/gzip-size
- Homepage: https://github.com/sindresorhus/gzip-size#readme
- Issues: https://github.com/sindresorhus/gzip-size/issues
- Funding: https://github.com/sponsors/sindresorhus
- npm.io page: https://npm.io/package/gzip-size

## Dependencies (1)

- [duplexer](https://npm.io/package/duplexer.md) ^0.1.2

## Alternatives

- [lodash.startswith](https://npm.io/package/lodash.startswith.md) — 769.7K weekly downloads
- [@tarojs/service](https://npm.io/package/@tarojs/service.md) — 33.9K weekly downloads
- [io.extendreality.tilia.indicators.spatialtargets.unity](https://npm.io/package/io.extendreality.tilia.indicators.spatialtargets.unity.md) — 131 weekly downloads
- [@rtarojs/taro](https://npm.io/package/@rtarojs/taro.md) — 90 weekly downloads
- [node-branch-io](https://npm.io/package/node-branch-io.md) — 50 weekly downloads

## Recent versions

- 7.0.0 (latest) — 2021-11-23
- 6.0.0 — 2020-11-16
- 5.1.1 — 2019-05-21
- 5.1.0 — 2019-04-15
- 5.0.0 — 2018-07-05
- 4.1.0 — 2017-11-22
- 4.0.1 — 2017-11-22
- 4.0.0 — 2017-09-08
- 3.0.0 — 2015-08-17
- 2.1.0 — 2015-08-14
- 2.0.3 — 2015-06-11
- 2.0.2 — 2015-06-10
- 2.0.1 — 2015-06-10
- 2.0.0 — 2015-06-10
- 1.0.0 — 2014-08-09
- … 3 more at https://npm.io/package/gzip-size/versions

## README

# gzip-size

> Get the gzipped size of a string or buffer

## Install

```sh
npm install gzip-size
```

## Usage

```js
import {gzipSize, gzipSizeSync} from 'gzip-size';

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.';

console.log(text.length);
//=> 191

console.log(gzipSizeSync(text));
//=> 78
```

## API

### gzipSize(input, options?)

Returns a `Promise<number>` with the size.

### gzipSizeSync(input, options?)

Returns the size.

#### input

Type: `string | Buffer`

#### options

Type: `object`

Any [`zlib` option](https://nodejs.org/api/zlib.html#zlib_class_options).

### gzipSizeFromFile(path, options?)

Returns a `Promise<number>` with the size of the file.

#### path

Type: `string`

### gzipSizeFromFileSync(path, options?)

Returns the size of the file.

### gzipSizeStream(options?)

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.

## Related

- [gzip-size-cli](https://github.com/sindresorhus/gzip-size-cli) - CLI for this module

---

<div align="center">
	<b>
		<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>
	</b>
	<br>
	<sub>
		Tidelift helps make open source sustainable for maintainers while giving companies<br>assurances about security, maintenance, and licensing for their dependencies.
	</sub>
</div>

---
_Source: https://npm.io/package/gzip-size · Machine-readable twin of the npm.io package page. Health data is recomputed on every publish._
