gunzip-maybe
Advanced tools
Comparing version 1.1.0 to 1.2.0
var zlib = require('zlib'); | ||
var peek = require('peek-stream') | ||
var through = require('through2') | ||
var pumpify = require('pumpify') | ||
@@ -12,6 +13,8 @@ var isGzipped = function(data) { | ||
module.exports = function() { | ||
var gunzip = function() { | ||
return peek({newline:false, maxBuffer:10}, function(data, swap) { | ||
swap(null, isGzipped(data) ? zlib.createGunzip() : through()) | ||
swap(null, isGzipped(data) ? pumpify(zlib.createGunzip(), gunzip()) : through()) | ||
}) | ||
} | ||
} | ||
module.exports = gunzip; |
{ | ||
"name": "gunzip-maybe", | ||
"description": "Transform stream that gunzips its input if it is gunzipped and just echoes it if not", | ||
"version": "1.1.0", | ||
"version": "1.2.0", | ||
"repository": "mafintosh/gunzip-maybe", | ||
@@ -9,2 +9,3 @@ "dependencies": { | ||
"peek-stream": "^1.1.0", | ||
"pumpify": "^1.3.3", | ||
"through2": "^0.4.1" | ||
@@ -11,0 +12,0 @@ }, |
11
test.js
@@ -17,2 +17,13 @@ var tape = require('tape'); | ||
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) { | ||
@@ -19,0 +30,0 @@ fs.createReadStream(__filename) |
4223
59
4
+ Addedpumpify@^1.3.3
+ Addedpump@2.0.1(transitive)
+ Addedpumpify@1.5.1(transitive)