-
-
Notifications
You must be signed in to change notification settings - Fork 20
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Require Node.js 12.20 and move to ESM
- Loading branch information
1 parent
fdb1ec1
commit 6b32b3f
Showing
7 changed files
with
170 additions
and
147 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,96 +1,103 @@ | ||
/// <reference types="node"/> | ||
import * as stream from 'stream'; | ||
import {ZlibOptions} from 'zlib'; | ||
|
||
declare namespace gzipSize { | ||
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; | ||
|
||
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; | ||
} | ||
} | ||
import {Buffer} from 'node:buffer'; | ||
import {PassThrough as PassThroughStream} from 'node:stream'; | ||
import {ZlibOptions} from 'node:zlib'; | ||
|
||
declare const gzipSize: { | ||
/** | ||
Get the gzipped size of a string or buffer. | ||
export type Options = ZlibOptions; | ||
|
||
@returns The gzipped size of `input`. | ||
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. | ||
*/ | ||
(input: string | Buffer, options?: gzipSize.Options): Promise<number>; | ||
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; | ||
} | ||
|
||
/** | ||
Synchronously get the gzipped size of a string or buffer. | ||
/** | ||
Get the gzipped size of a string or buffer. | ||
@returns The gzipped size of `input`. | ||
@returns The gzipped size of `input`. | ||
@example | ||
``` | ||
import gzipSize = require('gzip-size'); | ||
@example | ||
``` | ||
import {gzipSize} 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.'; | ||
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(text.length); | ||
//=> 191 | ||
console.log(gzipSize.sync(text)); | ||
//=> 78 | ||
``` | ||
*/ | ||
sync(input: string | Buffer, options?: gzipSize.Options): number; | ||
console.log(await gzipSize(text)); | ||
//=> 78 | ||
``` | ||
*/ | ||
export function gzipSize(input: string | Buffer, options?: Options): Promise<number>; | ||
|
||
/** | ||
@returns A stream that emits a `gzip-size` event and has a `gzipSize` property. | ||
*/ | ||
stream(options?: gzipSize.Options): gzipSize.GzipSizeStream; | ||
/** | ||
Synchronously get the gzipped size of a string or buffer. | ||
/** | ||
Get the gzipped size of a file. | ||
@returns The gzipped size of `input`. | ||
@returns The size of the file. | ||
*/ | ||
file(path: string, options?: gzipSize.Options): Promise<number>; | ||
@example | ||
``` | ||
import {gzipSizeSync} from 'gzip-size'; | ||
/** | ||
Synchronously 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. | ||
*/ | ||
fileSync(path: string, options?: gzipSize.Options): number; | ||
}; | ||
console.log(text.length); | ||
//=> 191 | ||
console.log(gzipSizeSync(text)); | ||
//=> 78 | ||
``` | ||
*/ | ||
export function gzipSizeSync(input: string | Buffer, options?: Options): number; | ||
|
||
/** | ||
Get the gzipped size of a file. | ||
@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; | ||
|
||
export = gzipSize; | ||
/** | ||
@returns A stream that emits a `gzip-size` event and has a `gzipSize` property. | ||
*/ | ||
export function gzipSizeStream(options?: Options): GzipSizeStream; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,18 +1,19 @@ | ||
/* eslint-disable @typescript-eslint/no-unsafe-assignment, @typescript-eslint/no-unsafe-return */ | ||
import fs from 'node:fs'; | ||
import {expectType} from 'tsd'; | ||
import * as fs from 'fs'; | ||
import gzipSize = require('.'); | ||
import {gzipSize, gzipSizeSync, gzipSizeFromFile, gzipSizeFromFileSync, gzipSizeStream} from './index.js'; | ||
|
||
expectType<Promise<number>>(gzipSize('foo')); | ||
expectType<Promise<number>>(gzipSize('foo', {chunkSize: 1})); | ||
expectType<number>(gzipSize.sync('foo')); | ||
expectType<number>(gzipSize.sync('foo', {chunkSize: 1})); | ||
expectType<number>(gzipSizeSync('foo')); | ||
expectType<number>(gzipSizeSync('foo', {chunkSize: 1})); | ||
const gstream = fs | ||
.createReadStream('index.d.ts') | ||
.pipe(gzipSize.stream()) | ||
.pipe(gzipSize.stream({chunkSize: 1})) | ||
.pipe(gzipSizeStream()) | ||
.pipe(gzipSizeStream({chunkSize: 1})) | ||
.on('gzip-size', size => expectType<number>(size)); | ||
expectType<number | undefined>(gstream.gzipSize); | ||
expectType<Promise<number>>(gzipSize.file('index.d.ts')); | ||
expectType<Promise<number>>(gzipSize.file('index.d.ts', {chunkSize: 1})); | ||
expectType<number>(gzipSize.fileSync('index.d.ts')); | ||
expectType<number>(gzipSize.fileSync('index.d.ts', {chunkSize: 1})); | ||
expectType<Promise<number>>(gzipSizeFromFile('index.d.ts')); | ||
expectType<Promise<number>>(gzipSizeFromFile('index.d.ts', {chunkSize: 1})); | ||
expectType<number>(gzipSizeFromFileSync('index.d.ts')); | ||
expectType<number>(gzipSizeFromFileSync('index.d.ts', {chunkSize: 1})); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.