Giter VIP home page Giter VIP logo

gzip-size's Introduction

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.

Related


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.

gzip-size's People

Contributors

arthurvr avatar bendingbender avatar bradtgmurray avatar devongovett avatar dy avatar kevva avatar marapper avatar okize avatar realityking avatar richienb avatar shrynx avatar sindresorhus avatar tikotzky avatar turbo87 avatar zertosh avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar

gzip-size's Issues

Version 7 is incompatible with "commonjs" typescript compiler

I have an error when trying to compile code using this module on node v16.17.1 on MacOS 13.1 with following setup (version 6 working just fine):

Error [ERR_REQUIRE_ESM]: require() of ES Module .../my-project/node_modules/gzip-size/my-file.js from .../my-project/src/my-file.js not supported.
Instead change the require of index.js in .../my-project/src/my-file.js to a dynamic import() which is available in all CommonJS modules.

My setup (to reproduce):

// package.json
{
    ...
    "dependencies": {
        ...
        "gzip-size": "^7.0.0",
    },
// tsconfig.json (https://www.npmjs.com/package/@tsconfig/recommended)
{
    "compilerOptions": {
        "target": "ES2015",
        "module": "commonjs",
        "strict": true,
        "esModuleInterop": true,
        "skipLibCheck": true,
        "forceConsistentCasingInFileNames": true
    },
    "include": ["src"],
    "exclude": ["node_modules", "**/__tests__/*"]
}
// my-file.ts
import { gzipSizeSync } from "gzip-size";
console.log(gzipSizeSync)

Add `.file()` method

I think it would be useful to add a path() method that did something like:

function path(path, options) {
  return new Promise((resolve, reject) => {
    let stream = fs.createReadStream(path);
    stream.on('error', reject);
    stream.pipe(gzipSize.stream(options)).on('gzip-size', resolve);
  });
}

Would that be a welcome PR?

Doesn't seem to work with ESM builds for nodejs env

Since it is using deprecated Duplexer library, (with 15M weekly downloads btw) which has only CJS build to it.

Building my package with tsup (goes through fine) and trying to run the "binary", I get the following error message:

throw Error('Dynamic require of "' + x + '" is not supported');
        ^
Error: Dynamic require of "stream" is not supported

First line of duplexer's build is:

var Stream = require("stream")

And it is causing problems.

My ts config uses NodeNext as module and moduleResolution, and I have "type": "module" in package.json.

Once I drop gzip-size import from my code, all builds and works fine.

Let me know how I can help and thank you for the library! ❤️

Seemingly related issue with esbuild. I use tsup but these are similar tools.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.