Socket
Socket
Sign inDemoInstall

gzip-size

Package Overview
Dependencies
1
Maintainers
1
Versions
18
Alerts
File Explorer

Advanced tools

Install Socket

Detect and block malicious and high-risk dependencies

Install

gzip-size

Get the gzipped size of a string or buffer


Version published
Maintainers
1
Weekly downloads
10,588,315
decreased by-6.67%

Weekly downloads

Package description

What is gzip-size?

The gzip-size npm package allows you to easily calculate the compressed size of a string or buffer using gzip compression. This can be particularly useful for assessing the size of files or assets in web development, ensuring that your resources are optimized for performance by evaluating their size after compression.

What are gzip-size's main functionalities?

Get the compressed size of a string

This feature allows you to calculate the gzip-compressed size of a string. It's useful for quickly assessing how much space a piece of text will take up after compression.

const gzipSize = require('gzip-size');
const string = 'Hello, world!';
gzipSize(string).then(size => {
  console.log(`Compressed size: ${size} bytes`);
});

Get the compressed size of a file

This feature calculates the gzip-compressed size of a file's contents. It's particularly useful for web developers looking to optimize their assets for performance by understanding the size impact of compression.

const gzipSize = require('gzip-size');
const fs = require('fs');

fs.readFile('file.txt', 'utf8', (err, data) => {
  if (err) {
    throw err;
  }
  gzipSize(data).then(size => {
    console.log(`Compressed size: ${size} bytes`);
  });
});

Synchronous API for getting compressed size

gzip-size also offers a synchronous API, allowing for immediate calculation of the compressed size without dealing with promises. This can be handy for scripts and applications where asynchronous handling is not necessary or desired.

const gzipSize = require('gzip-size');
const string = 'Hello, world!';
const size = gzipSize.sync(string);
console.log(`Compressed size: ${size} bytes`);

Other packages similar to gzip-size

Readme

Source

gzip-size

Get the gzipped size of a string or buffer

Install

npm install gzip-size

Usage

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.

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. The stream emits a gzip-size event and has a gzipSize property.

  • gzip-size-cli - CLI for this module

Get professional support for this package with a Tidelift subscription
Tidelift helps make open source sustainable for maintainers while giving companies
assurances about security, maintenance, and licensing for their dependencies.

Keywords

FAQs

Last updated on 23 Nov 2021

Did you know?

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc