gzip-isize
TypeScript icon, indicating that this package has built-in type declarations

1.0.2 • Public • Published

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.

Package Sidebar

Install

npm i gzip-isize

Weekly Downloads

40

Version

1.0.2

License

MIT

Unpacked Size

17 kB

Total Files

17

Last publish

Collaborators

  • rarecoil