UNPKG

3.15 kBTypeScriptView Raw
1import {Buffer} from 'node:buffer';
2import {PassThrough as PassThroughStream} from 'node:stream';
3import {ZlibOptions} from 'node:zlib';
4
5export type Options = ZlibOptions;
6
7export interface GzipSizeStream extends PassThroughStream {
8 /**
9 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.
10 */
11 gzipSize?: number;
12
13 addListener(event: 'gzip-size', listener: (size: number) => void): this;
14 addListener(
15 event: string | symbol,
16 listener: (...args: any[]) => void
17 ): this;
18 on(event: 'gzip-size', listener: (size: number) => void): this;
19 on(event: string | symbol, listener: (...args: any[]) => void): this;
20 once(event: 'gzip-size', listener: (size: number) => void): this;
21 once(event: string | symbol, listener: (...args: any[]) => void): this;
22 removeListener(event: 'gzip-size', listener: (size: number) => void): this;
23 removeListener(
24 event: string | symbol,
25 listener: (...args: any[]) => void
26 ): this;
27 off(event: 'gzip-size', listener: (size: number) => void): this;
28 off(event: string | symbol, listener: (...args: any[]) => void): this;
29 emit(event: 'gzip-size', size: number): boolean;
30 emit(event: string | symbol, ...args: any[]): boolean;
31 prependListener(event: 'gzip-size', listener: (size: number) => void): this;
32 prependListener(
33 event: string | symbol,
34 listener: (...args: any[]) => void
35 ): this;
36 prependOnceListener(
37 event: 'gzip-size',
38 listener: (size: number) => void
39 ): this;
40 prependOnceListener(
41 event: string | symbol,
42 listener: (...args: any[]) => void
43 ): this;
44}
45
46/**
47Get the gzipped size of a string or buffer.
48
49@returns The gzipped size of `input`.
50
51@example
52```
53import {gzipSize} from 'gzip-size';
54
55const 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.';
56
57console.log(text.length);
58//=> 191
59
60console.log(await gzipSize(text));
61//=> 78
62```
63*/
64export function gzipSize(input: string | Buffer, options?: Options): Promise<number>;
65
66/**
67Synchronously get the gzipped size of a string or buffer.
68
69@returns The gzipped size of `input`.
70
71@example
72```
73import {gzipSizeSync} from 'gzip-size';
74
75const 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.';
76
77console.log(text.length);
78//=> 191
79
80console.log(gzipSizeSync(text));
81//=> 78
82```
83*/
84export function gzipSizeSync(input: string | Buffer, options?: Options): number;
85
86/**
87Get the gzipped size of a file.
88
89@returns The size of the file.
90*/
91export function gzipSizeFromFile(filePath: string, options?: Options): Promise<number>;
92
93/**
94Synchronously get the gzipped size of a file.
95
96@returns The size of the file.
97*/
98export function gzipSizeFromFileSync(filePath: string, options?: Options): number;
99
100/**
101@returns A stream that emits a `gzip-size` event and has a `gzipSize` property.
102*/
103export function gzipSizeStream(options?: Options): GzipSizeStream;