update
This commit is contained in:
+5
-5
@@ -6,6 +6,11 @@ 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,
|
||||
@@ -37,11 +42,6 @@ declare namespace gzipSize {
|
||||
event: string | symbol,
|
||||
listener: (...args: any[]) => void
|
||||
): this;
|
||||
|
||||
/**
|
||||
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;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
+7
-5
@@ -2,17 +2,19 @@
|
||||
const fs = require('fs');
|
||||
const stream = require('stream');
|
||||
const zlib = require('zlib');
|
||||
const {promisify} = require('util');
|
||||
const duplexer = require('duplexer');
|
||||
const pify = require('pify');
|
||||
|
||||
const getOptions = options => Object.assign({level: 9}, options);
|
||||
const getOptions = options => ({level: 9, ...options});
|
||||
const gzip = promisify(zlib.gzip);
|
||||
|
||||
module.exports = (input, options) => {
|
||||
module.exports = async (input, options) => {
|
||||
if (!input) {
|
||||
return Promise.resolve(0);
|
||||
return 0;
|
||||
}
|
||||
|
||||
return pify(zlib.gzip)(input, getOptions(options)).then(data => data.length).catch(_ => 0);
|
||||
const data = await gzip(input, getOptions(options));
|
||||
return data.length;
|
||||
};
|
||||
|
||||
module.exports.sync = (input, options) => zlib.gzipSync(input, getOptions(options)).length;
|
||||
|
||||
+1
-1
@@ -1,6 +1,6 @@
|
||||
MIT License
|
||||
|
||||
Copyright (c) Sindre Sorhus <sindresorhus@gmail.com> (sindresorhus.com)
|
||||
Copyright (c) Sindre Sorhus <sindresorhus@gmail.com> (https://sindresorhus.com)
|
||||
|
||||
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
|
||||
|
||||
|
||||
+20
-20
@@ -1,58 +1,58 @@
|
||||
{
|
||||
"_args": [
|
||||
[
|
||||
"gzip-size@5.1.1",
|
||||
"/mnt/Foxconn/Digitalent/Deverloper/liff-push_2series"
|
||||
"gzip-size@6.0.0",
|
||||
"/home/node/nuxt"
|
||||
]
|
||||
],
|
||||
"_from": "gzip-size@5.1.1",
|
||||
"_id": "gzip-size@5.1.1",
|
||||
"_from": "gzip-size@6.0.0",
|
||||
"_id": "gzip-size@6.0.0",
|
||||
"_inBundle": false,
|
||||
"_integrity": "sha512-FNHi6mmoHvs1mxZAds4PpdCS6QG8B4C1krxJsMutgxl5t3+GlRTzzI3NEkifXx2pVsOvJdOGSmIgDhQ55FwdPA==",
|
||||
"_integrity": "sha512-ax7ZYomf6jqPTQ4+XCpUGyXKHk5WweS+e05MBO4/y3WJ5RkmPXNKvX+bx1behVILVwr6JSQvZAku021CHPXG3Q==",
|
||||
"_location": "/gzip-size",
|
||||
"_phantomChildren": {},
|
||||
"_requested": {
|
||||
"type": "version",
|
||||
"registry": true,
|
||||
"raw": "gzip-size@5.1.1",
|
||||
"raw": "gzip-size@6.0.0",
|
||||
"name": "gzip-size",
|
||||
"escapedName": "gzip-size",
|
||||
"rawSpec": "5.1.1",
|
||||
"rawSpec": "6.0.0",
|
||||
"saveSpec": null,
|
||||
"fetchSpec": "5.1.1"
|
||||
"fetchSpec": "6.0.0"
|
||||
},
|
||||
"_requiredBy": [
|
||||
"/webpack-bundle-analyzer"
|
||||
],
|
||||
"_resolved": "https://registry.npmjs.org/gzip-size/-/gzip-size-5.1.1.tgz",
|
||||
"_spec": "5.1.1",
|
||||
"_where": "/mnt/Foxconn/Digitalent/Deverloper/liff-push_2series",
|
||||
"_resolved": "https://registry.npmjs.org/gzip-size/-/gzip-size-6.0.0.tgz",
|
||||
"_spec": "6.0.0",
|
||||
"_where": "/home/node/nuxt",
|
||||
"author": {
|
||||
"name": "Sindre Sorhus",
|
||||
"email": "sindresorhus@gmail.com",
|
||||
"url": "sindresorhus.com"
|
||||
"url": "https://sindresorhus.com"
|
||||
},
|
||||
"bugs": {
|
||||
"url": "https://github.com/sindresorhus/gzip-size/issues"
|
||||
},
|
||||
"dependencies": {
|
||||
"duplexer": "^0.1.1",
|
||||
"pify": "^4.0.1"
|
||||
"duplexer": "^0.1.2"
|
||||
},
|
||||
"description": "Get the gzipped size of a string or buffer",
|
||||
"devDependencies": {
|
||||
"ava": "^1.4.1",
|
||||
"p-event": "^2.1.0",
|
||||
"tsd": "^0.7.2",
|
||||
"xo": "^0.24.0"
|
||||
"ava": "^2.4.0",
|
||||
"p-event": "^4.2.0",
|
||||
"tsd": "^0.13.1",
|
||||
"xo": "^0.34.2"
|
||||
},
|
||||
"engines": {
|
||||
"node": ">=6"
|
||||
"node": ">=10"
|
||||
},
|
||||
"files": [
|
||||
"index.js",
|
||||
"index.d.ts"
|
||||
],
|
||||
"funding": "https://github.com/sponsors/sindresorhus",
|
||||
"homepage": "https://github.com/sindresorhus/gzip-size#readme",
|
||||
"keywords": [
|
||||
"app",
|
||||
@@ -73,5 +73,5 @@
|
||||
"scripts": {
|
||||
"test": "xo && ava && tsd"
|
||||
},
|
||||
"version": "5.1.1"
|
||||
"version": "6.0.0"
|
||||
}
|
||||
|
||||
+20
-17
@@ -1,15 +1,13 @@
|
||||
# gzip-size [](https://travis-ci.org/sindresorhus/gzip-size)
|
||||
# gzip-size [](https://travis-ci.com/github/sindresorhus/gzip-size)
|
||||
|
||||
> Get the gzipped size of a string or buffer
|
||||
|
||||
|
||||
## Install
|
||||
|
||||
```
|
||||
$ npm install gzip-size
|
||||
```
|
||||
|
||||
|
||||
## Usage
|
||||
|
||||
```js
|
||||
@@ -24,49 +22,54 @@ console.log(gzipSize.sync(text));
|
||||
//=> 78
|
||||
```
|
||||
|
||||
|
||||
## API
|
||||
|
||||
### gzipSize(input, [options])
|
||||
### gzipSize(input, options?)
|
||||
|
||||
Returns a `Promise` for the size.
|
||||
Returns a `Promise<number>` with the size.
|
||||
|
||||
### gzipSize.sync(input, [options])
|
||||
### gzipSize.sync(input, options?)
|
||||
|
||||
Returns the size.
|
||||
|
||||
#### input
|
||||
|
||||
Type: `string` `Buffer`
|
||||
Type: `string | Buffer`
|
||||
|
||||
#### options
|
||||
|
||||
Type: `Object`
|
||||
Type: `object`
|
||||
|
||||
Any [`zlib` option](https://nodejs.org/api/zlib.html#zlib_class_options).
|
||||
|
||||
### gzipSize.stream([options])
|
||||
### gzipSize.stream(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])
|
||||
### gzipSize.file(path, options?)
|
||||
|
||||
Returns a `Promise` for the size of the file.
|
||||
Returns a `Promise<number>` with the size of the file.
|
||||
|
||||
#### path
|
||||
|
||||
Type: `string`
|
||||
|
||||
### gzipSize.fileSync(path, [options])
|
||||
### gzipSize.fileSync(path, options?)
|
||||
|
||||
Returns the size of the file.
|
||||
|
||||
|
||||
## Related
|
||||
|
||||
- [gzip-size-cli](https://github.com/sindresorhus/gzip-size-cli) - CLI for this module
|
||||
|
||||
---
|
||||
|
||||
## License
|
||||
|
||||
MIT © [Sindre Sorhus](https://sindresorhus.com)
|
||||
<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>
|
||||
|
||||
Reference in New Issue
Block a user