Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

gunzip-maybe

Package Overview
Dependencies
Maintainers
2
Versions
13
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

gunzip-maybe - npm Package Compare versions

Comparing version 1.2.1 to 1.3.0

2

bin.js

@@ -18,2 +18,2 @@ #!/usr/bin/env node

input.pipe(gunzip()).pipe(process.stdout)
input.pipe(gunzip()).pipe(process.stdout)

@@ -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

@@ -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

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc