Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

gzip-size

Package Overview
Dependencies
Maintainers
1
Versions
18
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

gzip-size - npm Package Compare versions

Comparing version 6.0.0 to 7.0.0

163

index.d.ts

@@ -1,96 +0,103 @@

/// <reference types="node"/>
import * as stream from 'stream';
import {ZlibOptions} from 'zlib';
import {Buffer} from 'node:buffer';
import {PassThrough as PassThroughStream} from 'node:stream';
import {ZlibOptions} from 'node:zlib';
declare namespace gzipSize {
type Options = ZlibOptions;
export type Options = ZlibOptions;
interface GzipSizeStream extends stream.PassThrough {
/**
Contains the gzip size of the stream after it is finished. Since this happens asynchronously, it is recommended you use the `gzip-size` event instead.
*/
gzipSize?: number;
export interface GzipSizeStream extends PassThroughStream {
/**
Contains the gzip size of the stream after it is finished. Since this happens asynchronously, it is recommended you use the `gzip-size` event instead.
*/
gzipSize?: number;
addListener(event: 'gzip-size', listener: (size: number) => void): this;
addListener(
event: string | symbol,
listener: (...args: any[]) => void
): this;
on(event: 'gzip-size', listener: (size: number) => void): this;
on(event: string | symbol, listener: (...args: any[]) => void): this;
once(event: 'gzip-size', listener: (size: number) => void): this;
once(event: string | symbol, listener: (...args: any[]) => void): this;
removeListener(event: 'gzip-size', listener: (size: number) => void): this;
removeListener(
event: string | symbol,
listener: (...args: any[]) => void
): this;
off(event: 'gzip-size', listener: (size: number) => void): this;
off(event: string | symbol, listener: (...args: any[]) => void): this;
emit(event: 'gzip-size', size: number): boolean;
emit(event: string | symbol, ...args: any[]): boolean;
prependListener(event: 'gzip-size', listener: (size: number) => void): this;
prependListener(
event: string | symbol,
listener: (...args: any[]) => void
): this;
prependOnceListener(
event: 'gzip-size',
listener: (size: number) => void
): this;
prependOnceListener(
event: string | symbol,
listener: (...args: any[]) => void
): this;
}
addListener(event: 'gzip-size', listener: (size: number) => void): this;
addListener(
event: string | symbol,
listener: (...args: any[]) => void
): this;
on(event: 'gzip-size', listener: (size: number) => void): this;
on(event: string | symbol, listener: (...args: any[]) => void): this;
once(event: 'gzip-size', listener: (size: number) => void): this;
once(event: string | symbol, listener: (...args: any[]) => void): this;
removeListener(event: 'gzip-size', listener: (size: number) => void): this;
removeListener(
event: string | symbol,
listener: (...args: any[]) => void
): this;
off(event: 'gzip-size', listener: (size: number) => void): this;
off(event: string | symbol, listener: (...args: any[]) => void): this;
emit(event: 'gzip-size', size: number): boolean;
emit(event: string | symbol, ...args: any[]): boolean;
prependListener(event: 'gzip-size', listener: (size: number) => void): this;
prependListener(
event: string | symbol,
listener: (...args: any[]) => void
): this;
prependOnceListener(
event: 'gzip-size',
listener: (size: number) => void
): this;
prependOnceListener(
event: string | symbol,
listener: (...args: any[]) => void
): this;
}
declare const gzipSize: {
/**
Get the gzipped size of a string or buffer.
/**
Get the gzipped size of a string or buffer.
@returns The gzipped size of `input`.
*/
(input: string | Buffer, options?: gzipSize.Options): Promise<number>;
@returns The gzipped size of `input`.
/**
Synchronously get the gzipped size of a string or buffer.
@example
```
import {gzipSize} from 'gzip-size';
@returns The gzipped size of `input`.
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.';
@example
```
import gzipSize = require('gzip-size');
console.log(text.length);
//=> 191
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(await gzipSize(text));
//=> 78
```
*/
export function gzipSize(input: string | Buffer, options?: Options): Promise<number>;
console.log(text.length);
//=> 191
/**
Synchronously get the gzipped size of a string or buffer.
console.log(gzipSize.sync(text));
//=> 78
```
*/
sync(input: string | Buffer, options?: gzipSize.Options): number;
@returns The gzipped size of `input`.
/**
@returns A stream that emits a `gzip-size` event and has a `gzipSize` property.
*/
stream(options?: gzipSize.Options): gzipSize.GzipSizeStream;
@example
```
import {gzipSizeSync} from 'gzip-size';
/**
Get the gzipped size of a file.
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.';
@returns The size of the file.
*/
file(path: string, options?: gzipSize.Options): Promise<number>;
console.log(text.length);
//=> 191
/**
Synchronously get the gzipped size of a file.
console.log(gzipSizeSync(text));
//=> 78
```
*/
export function gzipSizeSync(input: string | Buffer, options?: Options): number;
@returns The size of the file.
*/
fileSync(path: string, options?: gzipSize.Options): number;
};
/**
Get the gzipped size of a file.
export = gzipSize;
@returns The size of the file.
*/
export function gzipSizeFromFile(filePath: string, options?: Options): Promise<number>;
/**
Synchronously get the gzipped size of a file.
@returns The size of the file.
*/
export function gzipSizeFromFileSync(filePath: string, options?: Options): number;
/**
@returns A stream that emits a `gzip-size` event and has a `gzipSize` property.
*/
export function gzipSizeStream(options?: Options): GzipSizeStream;

@@ -1,7 +0,6 @@

'use strict';
const fs = require('fs');
const stream = require('stream');
const zlib = require('zlib');
const {promisify} = require('util');
const duplexer = require('duplexer');
import fs from 'node:fs';
import stream from 'node:stream';
import zlib from 'node:zlib';
import {promisify} from 'node:util';
import duplexer from 'duplexer';

@@ -11,3 +10,3 @@ const getOptions = options => ({level: 9, ...options});

module.exports = async (input, options) => {
export async function gzipSize(input, options) {
if (!input) {

@@ -19,7 +18,28 @@ return 0;

return data.length;
};
}
module.exports.sync = (input, options) => zlib.gzipSync(input, getOptions(options)).length;
export function gzipSizeSync(input, options) {
return zlib.gzipSync(input, getOptions(options)).length;
}
module.exports.stream = options => {
export function gzipSizeFromFile(path, options) {
// TODO: Use `stream.pipeline` here.
return new Promise((resolve, reject) => {
const stream = fs.createReadStream(path);
stream.on('error', reject);
const gzipStream = stream.pipe(gzipSizeStream(options));
gzipStream.on('error', reject);
gzipStream.on('gzip-size', resolve);
});
}
export function gzipSizeFromFileSync(path, options) {
return gzipSizeSync(fs.readFileSync(path), options);
}
export function gzipSizeStream(options) {
// TODO: Use `stream.pipeline` here.
const input = new stream.PassThrough();

@@ -47,15 +67,2 @@ const output = new stream.PassThrough();

return wrapper;
};
module.exports.file = (path, options) => {
return new Promise((resolve, reject) => {
const stream = fs.createReadStream(path);
stream.on('error', reject);
const gzipStream = stream.pipe(module.exports.stream(options));
gzipStream.on('error', reject);
gzipStream.on('gzip-size', resolve);
});
};
module.exports.fileSync = (path, options) => module.exports.sync(fs.readFileSync(path), options);
}
{
"name": "gzip-size",
"version": "6.0.0",
"version": "7.0.0",
"description": "Get the gzipped size of a string or buffer",

@@ -13,4 +13,6 @@ "license": "MIT",

},
"type": "module",
"exports": "./index.js",
"engines": {
"node": ">=10"
"node": "^12.20.0 || ^14.13.1 || >=16.0.0"
},

@@ -38,7 +40,7 @@ "scripts": {

"devDependencies": {
"ava": "^2.4.0",
"p-event": "^4.2.0",
"tsd": "^0.13.1",
"xo": "^0.34.2"
"ava": "^3.15.0",
"p-event": "^5.0.1",
"tsd": "^0.19.0",
"xo": "^0.46.4"
}
}

@@ -1,2 +0,2 @@

# gzip-size [![Build Status](https://travis-ci.com/sindresorhus/gzip-size.svg?branch=master)](https://travis-ci.com/github/sindresorhus/gzip-size)
# gzip-size

@@ -7,5 +7,5 @@ > Get the gzipped size of a string or buffer

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

@@ -15,3 +15,3 @@ ## Usage

```js
const gzipSize = require('gzip-size');
import {gzipSize, gzipSizeSync} from 'gzip-size';

@@ -23,3 +23,3 @@ 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(gzipSize.sync(text));
console.log(gzipSizeSync(text));
//=> 78

@@ -34,3 +34,3 @@ ```

### gzipSize.sync(input, options?)
### gzipSizeSync(input, options?)

@@ -49,8 +49,4 @@ Returns the size.

### gzipSize.stream(options?)
### gzipSizeFromFile(path, 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.
### gzipSize.file(path, options?)
Returns a `Promise<number>` with the size of the file.

@@ -62,6 +58,10 @@

### gzipSize.fileSync(path, options?)
### 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

@@ -68,0 +68,0 @@

SocketSocket SOC 2 Logo

Product

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

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc