package/LICENSE000644 0000002067 3560116604 010272 0ustar00000000 000000 The MIT License (MIT) Copyright (c) 2016 Mathias Buus Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. package/bin.js000755 0000000713 3560116604 010372 0ustar00000000 000000 #!/usr/bin/env node var fs = require('fs') var filename = process.argv[2] var gunzip = require('./') if (filename === '--help') { console.log('Usage: gunzip-maybe filename?') console.log('') console.log(' cat somefile | gunzip-maybe') console.log(' gunzip-maybe somefile') console.log('') process.exit(0) } var input = (!filename || filename === '-') ? process.stdin : fs.createReadStream(filename) input.pipe(gunzip()).pipe(process.stdout) package/index.js000644 0000001553 3560116604 010731 0ustar00000000 000000 var zlib = require('zlib') var peek = require('peek-stream') var through = require('through2') var pumpify = require('pumpify') var isGzip = require('is-gzip') var isDeflate = require('is-deflate') var isCompressed = function (data) { if (isGzip(data)) return 1 if (isDeflate(data)) return 2 return 0 } var gunzip = function (maxRecursion) { if (maxRecursion === undefined) maxRecursion = 3 return peek({newline: false, maxBuffer: 10}, function (data, swap) { if (maxRecursion < 0) return swap(new Error('Maximum recursion reached')) switch (isCompressed(data)) { case 1: swap(null, pumpify(zlib.createGunzip(), gunzip(maxRecursion - 1))) break case 2: swap(null, pumpify(zlib.createInflate(), gunzip(maxRecursion - 1))) break default: swap(null, through()) } }) } module.exports = gunzip package/test.js000644 0000003230 3560116604 010573 0ustar00000000 000000 var tape = require('tape') var zlib = require('zlib') var concat = require('concat-stream') var fs = require('fs') var gunzip = require('./') 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('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('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() })) }) tape('limited recursion', function (t) { t.plan(1) fs.createReadStream(__filename) .pipe(zlib.createGzip()) .pipe(zlib.createGzip()) .pipe(gunzip(1)) .on('finish', function () { t.fail('should not finish') }) .on('error', function (err) { t.same(err.message, 'Maximum recursion reached') }) }) package/package.json000644 0000001723 3560116604 011551 0ustar00000000 000000 { "name": "gunzip-maybe", "description": "Transform stream that gunzips its input if it is gzipped and just echoes it if not", "version": "1.4.2", "repository": { "type": "git", "url": "https://github.com/mafintosh/gunzip-maybe" }, "license": "MIT", "dependencies": { "browserify-zlib": "^0.1.4", "is-deflate": "^1.0.0", "is-gzip": "^1.0.0", "peek-stream": "^1.1.0", "pumpify": "^1.3.3", "through2": "^2.0.3" }, "devDependencies": { "concat-stream": "^1.4.5", "standard": "^9.0.0", "tape": "^4.6.3" }, "scripts": { "test": "standard && tape test.js" }, "bin": { "gunzip-maybe": "./bin.js" }, "browser": { "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": [ 55.6666904, 12.5797771 ] } package/README.md000644 0000001641 3560116604 010541 0ustar00000000 000000 # gunzip-maybe Transform stream that gunzips its input if it is gzipped and just echoes it if not. ``` npm install 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) ## Usage Simply pipe a gzipped (or not gzipped) stream to `gunzip([maxRecursion = 3])` and read the unzipped content. `maxRecursion` protects the unzip mechanism from an infinite recursion in case of a malicious archive. ``` js // this will gunzip gzippedStream gzippedStream.pipe(gunzip()).pipe(process.stdout); // this will just echo plainTextStream plainTextStream.pipe(gunzip()).pipe(process.stdout); ``` ## CLI usage ``` npm install -g gunzip-maybe gunzip-maybe --help # will print out usage ``` ## License MIT package/.travis.yml000644 0000000072 3560116604 011370 0ustar00000000 000000 language: node_js node_js: - "0.10" script: "npm test"