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

compression-zlib

Package Overview
Dependencies
Maintainers
1
Versions
10
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

compression-zlib - npm Package Compare versions

Comparing version 2.0.2 to 2.1.0

12

History.md

@@ -0,1 +1,13 @@

v2.1.0 / 2015-06-26
==================
* Fix return value from `.end` and `.write` after end
* Improve detection of zero-length body without `Content-Length`
* Remove flush reassignment
* Simplify threshold detection
* Update `bytes`@2.1.0
* Update `accepts`@1.2.9
* Update `compressible`@2.0.3
* Update `debug`@2.2.0
v2.0.2 / 2015-04-26

@@ -2,0 +14,0 @@ ==================

78

index.js

@@ -36,7 +36,12 @@ 'use strict';

/**
* No-operation function
* Get the length of a given chunk
*/
function noop() {
function chunkLength(chunk, encoding) {
return;
if (!chunk) {
return 0;
}
return !Buffer.isBuffer(chunk) ? Buffer.byteLength(chunk, encoding)
: chunk.length;
}

@@ -69,3 +74,4 @@

var compress = true;
var ended = false;
var length;
var listeners = [];

@@ -77,20 +83,17 @@ var write = res.write;

// see #8
req.on('close', function() {
// flush
res.flush = function flush() {
res.write = res.end = noop;
return;
});
if (stream) {
stream.flush();
}
};
// flush is noop by default
res.flush = noop;
// proxy
res.write = function(chunk, encoding) {
if (ended === true) {
return false;
}
if (!this._header) {
// if content-length is set and is lower
// than the threshold, don't compress
var len = Number(res.getHeader('Content-Length'));
checkthreshold(len);
this._implicitHeader();

@@ -104,16 +107,21 @@ }

var len;
if (chunk) {
len = Buffer.isBuffer(chunk) ? chunk.length : Buffer.byteLength(chunk,
encoding);
if (ended === true) {
return false;
}
if (!this._header) {
len = Number(this.getHeader('Content-Length')) || len;
checkthreshold(len);
// estimate the length
if (!this.getHeader('Content-Length')) {
length = chunkLength(chunk, encoding);
}
this._implicitHeader();
}
if (!stream) {
return end.call(res, chunk, encoding);
return end.call(this, chunk, encoding);
}
// mark ended
ended = true;
// write Buffer for Node.js 0.8

@@ -138,14 +146,5 @@ return chunk ? stream.end(new Buffer(chunk, encoding)) : stream.end();

function checkthreshold(len) {
if (compress && len < threshold) {
debug('size below threshold');
compress = false;
}
return;
}
function nocompress(msg) {
debug('no compression' + (msg ? ': ' + msg : ''));
debug('no compression: %s', msg);
addListeners(res, on, listeners);

@@ -166,4 +165,7 @@ listeners = null;

if (!compress) {
return nocompress();
// content-length below threshold
if (Number(res.getHeader('Content-Length')) < threshold
|| length < threshold) {
nocompress('size below threshold');
return;
}

@@ -201,8 +203,2 @@

// overwrite the flush method
res.flush = function() {
return stream.flush();
};
// header fields

@@ -209,0 +205,0 @@ res.setHeader('Content-Encoding', method);

{
"version": "2.0.2",
"version": "2.1.0",
"name": "compression-zlib",

@@ -26,6 +26,6 @@ "description": "Node.js compression middleware",

"dependencies": {
"accepts": "1.2.5",
"bytes": "2.0.0",
"compressible": "2.0.2",
"debug": "2.1.3",
"accepts": "1.2.9",
"bytes": "2.1.0",
"compressible": "2.0.3",
"debug": "2.2.0",
"on-headers": "1.0.0",

@@ -37,4 +37,4 @@ "vary": "1.0.0"

"istanbul": "~0.3",
"mocha": "~2.1",
"supertest": "~0.15"
"mocha": "~2.2",
"supertest": "~1.0"
},

@@ -41,0 +41,0 @@ "engines": {

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