From fe95c258fb3c4a1b486dd334ece715ea753cafb8 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Tom=20Moitie=CC=81?= Date: Wed, 15 Jun 2016 16:49:21 +0100 Subject: [PATCH 1/2] Upgrade deps to their latest versions, and fix length bug --- index.js | 6 +++--- package.json | 10 +++++----- 2 files changed, 8 insertions(+), 8 deletions(-) diff --git a/index.js b/index.js index 5036935..6be0061 100644 --- a/index.js +++ b/index.js @@ -5,7 +5,7 @@ module.exports = function(options, onprogress) { if (typeof options === 'function') return module.exports(null, options); options = options || {}; - var length = options.length || 0; + var length = options.length || null; var time = options.time || 0; var drain = options.drain || false; var transferred = options.transferred || 0; @@ -57,12 +57,12 @@ module.exports = function(options, onprogress) { update.remaining = length - update.transferred; tr.emit('length', length); }; - + // Expose `onlength()` handler as `setLength()` to support custom use cases where length // is not known until after a few chunks have already been pumped, or is // calculated on the fly. tr.setLength = onlength; - + tr.on('pipe', function(stream) { if (typeof length === 'number') return; // Support http module diff --git a/package.json b/package.json index 6f85889..fb3be9c 100644 --- a/package.json +++ b/package.json @@ -20,13 +20,13 @@ ], "main": "index.js", "dependencies": { - "through2": "~0.2.3", - "speedometer": "~0.1.2" + "speedometer": "^1.0.0", + "through2": "^2.0.1" }, "devDependencies": { - "request": "~2.29.0", - "single-line-log": "~1.0.0", - "numeral": "~1.5.2" + "numeral": "~1.5.2", + "request": "^2.72.0", + "single-line-log": "^1.1.1" }, "scripts": { "test": "node test/http.js && node test/request.js" From 6427f1dd0c65aacfac86a1e6412642615b5f196b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Tom=20Moitie=CC=81?= Date: Thu, 16 Jun 2016 14:40:52 +0100 Subject: [PATCH 2/2] Revert change to default option, and check for option in the pipe --- index.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/index.js b/index.js index 6be0061..320dd72 100644 --- a/index.js +++ b/index.js @@ -5,7 +5,7 @@ module.exports = function(options, onprogress) { if (typeof options === 'function') return module.exports(null, options); options = options || {}; - var length = options.length || null; + var length = options.length || 0; var time = options.time || 0; var drain = options.drain || false; var transferred = options.transferred || 0; @@ -64,7 +64,7 @@ module.exports = function(options, onprogress) { tr.setLength = onlength; tr.on('pipe', function(stream) { - if (typeof length === 'number') return; + if (options.length && typeof length === 'number') return; // Support http module if (stream.readable && !stream.writable && stream.headers) { return onlength(parseInt(stream.headers['content-length'] || 0));