gunzip-maybe
Advanced tools
Comparing version 1.2.1 to 1.3.0
@@ -18,2 +18,2 @@ #!/usr/bin/env node | ||
input.pipe(gunzip()).pipe(process.stdout) | ||
input.pipe(gunzip()).pipe(process.stdout) |
29
index.js
@@ -1,2 +0,2 @@ | ||
var zlib = require('zlib'); | ||
var zlib = require('zlib') | ||
var peek = require('peek-stream') | ||
@@ -6,15 +6,24 @@ var through = require('through2') | ||
var isGzipped = function(data) { | ||
if (data.length < 10) return false // gzip header is 10 bytes | ||
if (data[0] !== 0x1f && data[1] !== 0x8b) return false // gzip magic bytes | ||
if (data[2] !== 8) return false // is deflating | ||
return true | ||
var isCompressed = function (data) { | ||
if (data.length < 10) return 0 // gzip header is 10 bytes | ||
if (data[0] === 0x1f && data[1] === 0x8b && data[2] === 8) return 1 // gzip magic bytes | ||
if (data[0] === 0x78 && (data[1] === 1 || data[1] === 0x9c || data[1] === 0xda)) return 2 // deflate magic bytes | ||
return 0 | ||
} | ||
var gunzip = function() { | ||
return peek({newline:false, maxBuffer:10}, function(data, swap) { | ||
swap(null, isGzipped(data) ? pumpify(zlib.createGunzip(), gunzip()) : through()) | ||
var gunzip = function () { | ||
return peek({newline: false, maxBuffer: 10}, function (data, swap) { | ||
switch (isCompressed(data)) { | ||
case 1: | ||
swap(null, pumpify(zlib.createGunzip(), gunzip())) | ||
break | ||
case 2: | ||
swap(null, pumpify(zlib.createInflate(), gunzip())) | ||
break | ||
default: | ||
swap(null, through()) | ||
} | ||
}) | ||
} | ||
module.exports = gunzip; | ||
module.exports = gunzip |
{ | ||
"name": "gunzip-maybe", | ||
"description": "Transform stream that gunzips its input if it is gzipped and just echoes it if not", | ||
"version": "1.2.1", | ||
"repository": "mafintosh/gunzip-maybe", | ||
"version": "1.3.0", | ||
"repository": { | ||
"type": "git", | ||
"url": "https://github.com/mafintosh/gunzip-maybe" | ||
}, | ||
"license": "MIT", | ||
"dependencies": { | ||
@@ -14,6 +18,7 @@ "browserify-zlib": "^0.1.4", | ||
"concat-stream": "^1.4.5", | ||
"standard": "^5.4.1", | ||
"tape": "^2.12.3" | ||
}, | ||
"scripts": { | ||
"test": "tape test.js" | ||
"test": "standard && tape test.js" | ||
}, | ||
@@ -25,3 +30,13 @@ "bin": { | ||
"zlib": "browserify-zlib" | ||
} | ||
}, | ||
"bugs": { | ||
"url": "https://github.com/mafintosh/gunzip-maybe/issues" | ||
}, | ||
"homepage": "https://github.com/mafintosh/gunzip-maybe", | ||
"main": "index.js", | ||
"author": "Mathias Buus (@mafintosh)", | ||
"coordinates": [ | ||
59.91695350000001, | ||
10.7400225 | ||
] | ||
} |
@@ -10,2 +10,3 @@ # gunzip-maybe | ||
[![build status](http://img.shields.io/travis/mafintosh/gunzip-maybe.svg?style=flat)](http://travis-ci.org/mafintosh/gunzip-maybe) | ||
[![js-standard-style](https://img.shields.io/badge/code%20style-standard-brightgreen.svg?style=flat)](https://github.com/feross/standard) | ||
@@ -12,0 +13,0 @@ ## Usage |
85
test.js
@@ -1,35 +0,56 @@ | ||
var tape = require('tape'); | ||
var zlib = require('zlib'); | ||
var concat = require('concat-stream'); | ||
var fs = require('fs'); | ||
var gunzip = require('./'); | ||
var tape = require('tape') | ||
var zlib = require('zlib') | ||
var concat = require('concat-stream') | ||
var fs = require('fs') | ||
var gunzip = require('./') | ||
tape('gunzipped input', function(t) { | ||
fs.createReadStream(__filename) | ||
.pipe(zlib.createGzip()) | ||
.pipe(gunzip()) | ||
.pipe(concat(function(data) { | ||
t.same(data, fs.readFileSync(__filename)); | ||
t.end(); | ||
})) | ||
}); | ||
tape('deflated input', function (t) { | ||
fs.createReadStream(__filename) | ||
.pipe(zlib.createDeflate()) | ||
.pipe(gunzip()) | ||
.pipe(concat(function (data) { | ||
t.same(data, fs.readFileSync(__filename)) | ||
t.end() | ||
})) | ||
}) | ||
tape('gunzipped multiple times', function(t) { | ||
fs.createReadStream(__filename) | ||
.pipe(zlib.createGzip()) | ||
.pipe(zlib.createGzip()) | ||
.pipe(gunzip()) | ||
.pipe(concat(function(data) { | ||
t.same(data, fs.readFileSync(__filename)); | ||
t.end(); | ||
})) | ||
}); | ||
tape('deflated multiple times', function (t) { | ||
fs.createReadStream(__filename) | ||
.pipe(zlib.createDeflate()) | ||
.pipe(zlib.createDeflate()) | ||
.pipe(gunzip()) | ||
.pipe(concat(function (data) { | ||
t.same(data, fs.readFileSync(__filename)) | ||
t.end() | ||
})) | ||
}) | ||
tape('regular input', function(t) { | ||
fs.createReadStream(__filename) | ||
.pipe(gunzip()) | ||
.pipe(concat(function(data) { | ||
t.same(data, fs.readFileSync(__filename)); | ||
t.end(); | ||
})) | ||
}); | ||
tape('gunzipped input', function (t) { | ||
fs.createReadStream(__filename) | ||
.pipe(zlib.createGzip()) | ||
.pipe(gunzip()) | ||
.pipe(concat(function (data) { | ||
t.same(data, fs.readFileSync(__filename)) | ||
t.end() | ||
})) | ||
}) | ||
tape('gunzipped multiple times', function (t) { | ||
fs.createReadStream(__filename) | ||
.pipe(zlib.createGzip()) | ||
.pipe(zlib.createGzip()) | ||
.pipe(gunzip()) | ||
.pipe(concat(function (data) { | ||
t.same(data, fs.readFileSync(__filename)) | ||
t.end() | ||
})) | ||
}) | ||
tape('regular input', function (t) { | ||
fs.createReadStream(__filename) | ||
.pipe(gunzip()) | ||
.pipe(concat(function (data) { | ||
t.same(data, fs.readFileSync(__filename)) | ||
t.end() | ||
})) | ||
}) |
Sorry, the diff of this file is not supported yet
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
New author
Supply chain riskA new npm collaborator published a version of the package for the first time. New collaborators are usually benign additions to a project, but do indicate a change to the security surface area of a package.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
No contributors or author data
MaintenancePackage does not specify a list of contributors or an author in package.json.
Found 1 instance in 1 package
No bug tracker
MaintenancePackage does not have a linked bug tracker in package.json.
Found 1 instance in 1 package
No repository
Supply chain riskPackage does not have a linked source code repository. Without this field, a package will have no reference to the location of the source code use to generate the package.
Found 1 instance in 1 package
No website
QualityPackage does not have a website.
Found 1 instance in 1 package
5535
90
0
0
35
2
3
1