compression-zlib
Advanced tools
Comparing version 2.0.2 to 2.1.0
@@ -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": { |
70673
365
+ Addedaccepts@1.2.9(transitive)
+ Addedbytes@2.1.0(transitive)
+ Addedcompressible@2.0.3(transitive)
+ Addeddebug@2.2.0(transitive)
+ Addedmime-db@1.52.0(transitive)
+ Addedmime-types@2.1.35(transitive)
+ Addedms@0.7.1(transitive)
+ Addednegotiator@0.5.3(transitive)
- Removedaccepts@1.2.5(transitive)
- Removedbytes@2.0.0(transitive)
- Removedcompressible@2.0.2(transitive)
- Removeddebug@2.1.3(transitive)
- Removedfunction-bind@1.1.2(transitive)
- Removedhasown@2.0.2(transitive)
- Removedis@3.3.0(transitive)
- Removedmime-db@1.12.0(transitive)
- Removedmime-types@2.0.14(transitive)
- Removedms@0.7.0(transitive)
- Removednegotiator@0.5.1(transitive)
- Removednode.extend@2.0.3(transitive)
Updatedaccepts@1.2.9
Updatedbytes@2.1.0
Updatedcompressible@2.0.3
Updateddebug@2.2.0