GithubHelp home page GithubHelp logo

rarecoil / gzip-isize Goto Github PK

View Code? Open in Web Editor NEW
0.0 2.0 0.0 568 KB

TypeScript-based, async-enabled module to get ISIZE from GZIP files.

License: MIT License

JavaScript 8.50% TypeScript 91.50%
gzip gzip-compression typescript npm-package npm-package-typescript gzip-validation

gzip-isize's Introduction

gzip-isize

Build Status Known Vulnerabilities

Get GZIP file size statistics without extracting the file.

This module uses the GZIP ISIZE record in order to get size and compression ratio statistics for a GZIPped file. This module is useful for validation when trying to get a sense of what a GZip file will decompress to without actually attempting to decompress it.

Other popular modules get the size by actually doing the work. On smaller systems with limited resources or when extracting untrusted GZIP files, you may inadvertently end up with resource exhaustion during the extraction process. This module's function makes a good first-line sanity check before deeper analysis during extraction.

Usage

gzip-isize is written in TypeScript, and thus works well with TypeScript-based applications. However, it is easy to use in the traditional Node.js way:

const isz = require('../dist/isize.js').ISize;

isz.get('../test/file.tgz')
    .then((result) => {
        console.log(result);
    });

TypeScript

import { ISize, GZipCompressionInfo, GZipError } from 'gzip-isize';

try {
    let fileInfo:GZipCompressionInfo = await ISize.get('/path/to/tarball.tgz');

    console.info(`Compression info for ${fileInfo.name}`);
    console.info(`Original file size: ${fileInfo.originalSize} bytes`);
    console.info(`Compressed size: ${fileInfo.compressedSize} bytes`);
    console.info(`Compression ratio: ${fileInfo.compressionRatio}`);
    console.info(`Compression ratio percent: ${fileInfo.compressionRatioPercent})%`);
}
catch (e:GZipError) {
    console.error(`Decompression error: ${e}`);
}

Additional Resources

License

MIT. © 2019 rarecoil.

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.