Skip to content

🍠 quickly test to see if a readable stream is gzipped based on its magic number

Notifications You must be signed in to change notification settings

catdad/is-gzip-stream

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

24 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

is-gzip-stream

Build Test Coverage Code Climate Downloads Version Dependency Status ISC License

Install

npm install --save is-gzip-stream

Usage

You can pass any readable stream into the module to determine if the stream contains gzipped content.

The module has to read some of the stream, meaning that you will not be able to use the entire stream if you wait to determine if the content is gzipped or not. To read the stream, you will need to use the stream provided by the lib. It is available both as a return value and in the callback, just in case.

var fs = require('fs');
var isGzipStream = require('is-gzip-stream');

var stream = fs.createReadStream('somefile');

stream = isGzipStream(stream, function(err, isGzipped) {
    // if there is no error, isGzipped will be a boolean
    
    // stream can provide the entire content of the original file
    // you can read the data as normal
});
var fs = require('fs');
var isGzipStream = require('is-gzip-stream');

var unknownStream = fs.createReadStream('somefile');

isGzipStream(unknownStream, function(err, isGzipped, knownStream) {
    // if there is no error, isGzipped will be a boolean
    
    // knownStream can provide the entire content of the original file,
    // and you can read it like normal
    
    // the original `stream` variable is still the same, though some data
    // has been read already, and you will not get the entire file if you
    // begin reading now
});

License

ISC

About

🍠 quickly test to see if a readable stream is gzipped based on its magic number

Topics

Resources

Stars

Watchers

Forks

Packages

No packages published