diff options
Diffstat (limited to 'node_modules/progress-stream')
-rw-r--r-- | node_modules/progress-stream/.npmignore | 2 | ||||
-rw-r--r-- | node_modules/progress-stream/LICENSE | 23 | ||||
-rw-r--r-- | node_modules/progress-stream/README.md | 163 | ||||
-rw-r--r-- | node_modules/progress-stream/index.js | 98 | ||||
-rw-r--r-- | node_modules/progress-stream/package.json | 36 | ||||
-rw-r--r-- | node_modules/progress-stream/test/http.js | 30 | ||||
-rw-r--r-- | node_modules/progress-stream/test/request.js | 20 |
7 files changed, 0 insertions, 372 deletions
diff --git a/node_modules/progress-stream/.npmignore b/node_modules/progress-stream/.npmignore deleted file mode 100644 index fd4f2b0..0000000 --- a/node_modules/progress-stream/.npmignore +++ /dev/null @@ -1,2 +0,0 @@ -node_modules -.DS_Store diff --git a/node_modules/progress-stream/LICENSE b/node_modules/progress-stream/LICENSE deleted file mode 100644 index 1207b39..0000000 --- a/node_modules/progress-stream/LICENSE +++ /dev/null @@ -1,23 +0,0 @@ -Copyright (c) Tobias Baunbæk <freeall@gmail.com> - -All rights reserved. - -Redistribution and use in source and binary forms, with or without modification, -are permitted provided that the following conditions are met: - -- Redistributions of source code must retain the above copyright notice, this - list of conditions and the following disclaimer. -- Redistributions in binary form must reproduce the above copyright notice, this - list of conditions and the following disclaimer in the documentation and/or - other materials provided with the distribution. - -THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND -ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED -WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE -DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR -ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES -(INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; -LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON -ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT -(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS -SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. diff --git a/node_modules/progress-stream/README.md b/node_modules/progress-stream/README.md deleted file mode 100644 index 85ca574..0000000 --- a/node_modules/progress-stream/README.md +++ /dev/null @@ -1,163 +0,0 @@ -# progress-stream - -Read the progress of a stream. Supports speed and eta. - -Gets the lengths of the stream automatically if you're using the request or http module. You can also pass the length on initiation. Progress-stream will also check to see if the stream already have a length property. - - npm install progress-stream - -## Usage - -This example copies a large file, and prints out the percentage, speed and remaining every 100ms. - -```js -var progress = require('progress-stream'); -var fs = require('fs'); - -var stat = fs.statSync(filename); -var str = progress({ - length: stat.size, - time: 100 -}); - -str.on('progress', function(progress) { - console.log(progress); - - /* - { - percentage: 9.05, - transferred: 949624, - length: 10485760, - remaining: 9536136, - eta: 42, - runtime: 3, - delta: 295396, - speed: 949624 - } - */ -}); - -fs.createReadStream(filename) - .pipe(str) - .pipe(fs.createWriteStream(output)); -``` - -## Methods - -### progress([options], [onprogress]) - -You can instantiate in two ways: - -``` js -var str = progress({time:100}); -str.on('progress', function(progress) { ... }); -``` - -or inline the progress listener - -``` js -var str = progress({time:100}, function(progress) { ... }); -``` - -## Properties - -### .progress - -You can get the progress from the progress property. - -``` js -var str = progress({time:100}); - -console.log(str.progress); - -/* -{ - percentage: 9.05, - transferred: 949624, - length: 10485760, - remaining: 9536136, - eta: 10, - runtime: 0, - delta: 295396, - speed: 949624 -} -*/ -``` - -## Events - -### on('progress', function(progress) { ... }) - -``` js -var str = progress({time:100}); -str.on('progress', function(progress) { ... }); -``` - -## Options - -### time(integer) - -Sets how often progress events is emitted. If omitted then defaults to emit every time a chunk is received. - -### speed(integer) - -Sets how long the speedometer needs to calculate the speed. Defaults to 5 sec. - -### length(integer) - -If you already know the length of the stream, then you can set it. Defaults to 0. - -### drain(boolean) - -In case you don't want to include a readstream after progress-stream, set to true to drain automatically. Defaults to false. - -### transferred(integer) - -If you want to set how much data have previous been downloaded. Useful for a resumed download. - -## Examples - -### Using the request module - -This example uses request to download a 100 MB file, and writes out the percentage every second. - -You can also find an example in `test/request.js`. - -``` js -var progress = require('progress-stream'); -var req = require('request'); -var fs = require('fs'); - -var str = progress({ - time: 1000 -}); - -str.on('progress', function(progress) { - console.log(Math.round(progress.percentage)+'%'); -}); - -req('http://cachefly.cachefly.net/100mb.test', { headers: { 'user-agent': 'test' }}) - .pipe(str) - .pipe(fs.createWriteStream('test.data')); -``` - -### Using the http module - -In `test/http.js` it's shown how to do it with the http module. - - -## Methods - - -### `setLength(newLength)` - -Sometimes, you don't know how big a stream is right away (e.g. multipart file uploads). You might find out after a few chunks have already passed through the stream, seconds or even minutes later. In this case, you can use the `setLength` method to recalculate the relevant tracked progress data. - -```js -var str = progress({}); -someFickleStreamInstance.pipe(str).pipe(fs.createWriteStream('test.data')); - -someFickleStreamInstance.on('conviction', function nowIKnowMyLength (actualLength) { - str.setLength(actualLength); -}); -``` diff --git a/node_modules/progress-stream/index.js b/node_modules/progress-stream/index.js deleted file mode 100644 index 5036935..0000000 --- a/node_modules/progress-stream/index.js +++ /dev/null @@ -1,98 +0,0 @@ -var through = require('through2'); -var speedometer = require('speedometer'); - -module.exports = function(options, onprogress) { - if (typeof options === 'function') return module.exports(null, options); - options = options || {}; - - var length = options.length || 0; - var time = options.time || 0; - var drain = options.drain || false; - var transferred = options.transferred || 0; - var nextUpdate = Date.now()+time; - var delta = 0; - var speed = speedometer(options.speed || 5000); - var startTime = Date.now(); - - var update = { - percentage: 0, - transferred: transferred, - length: length, - remaining: length, - eta: 0, - runtime: 0 - }; - - var emit = function(ended) { - update.delta = delta; - update.percentage = ended ? 100 : (length ? transferred/length*100 : 0); - update.speed = speed(delta); - update.eta = Math.round(update.remaining / update.speed); - update.runtime = parseInt((Date.now() - startTime)/1000); - nextUpdate = Date.now()+time; - - delta = 0; - - tr.emit('progress', update); - }; - var write = function(chunk, enc, callback) { - var len = options.objectMode ? 1 : chunk.length; - transferred += len; - delta += len; - update.transferred = transferred; - update.remaining = length >= transferred ? length - transferred : 0; - - if (Date.now() >= nextUpdate) emit(false); - callback(null, chunk); - }; - var end = function(callback) { - emit(true); - callback(); - }; - - var tr = through(options.objectMode ? {objectMode:true, highWaterMark:16} : {}, write, end); - var onlength = function(newLength) { - length = newLength; - update.length = length; - 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 - if (stream.readable && !stream.writable && stream.headers) { - return onlength(parseInt(stream.headers['content-length'] || 0)); - } - - // Support streams with a length property - if (typeof stream.length === 'number') { - return onlength(stream.length); - } - - // Support request module - stream.on('response', function(res) { - if (!res || !res.headers) return; - if (res.headers['content-encoding'] === 'gzip') return; - if (res.headers['content-length']) { - return onlength(parseInt(res.headers['content-length'])); - } - }); - }); - - if (drain) tr.resume(); - if (onprogress) tr.on('progress', onprogress); - - tr.progress = function() { - update.speed = speed(0); - update.eta = Math.round(update.remaining / update.speed); - - return update; - }; - return tr; -}; diff --git a/node_modules/progress-stream/package.json b/node_modules/progress-stream/package.json deleted file mode 100644 index 6f85889..0000000 --- a/node_modules/progress-stream/package.json +++ /dev/null @@ -1,36 +0,0 @@ -{ - "name": "progress-stream", - "version": "1.2.0", - "description": "Read the progress of a stream", - "repository": { - "type": "git", - "url": "git@github.com:freeall/progress-stream.git" - }, - "keywords": [ - "stream", - "progress", - "percentage", - "percent", - "download", - "upload", - "file", - "streaming", - "request", - "http" - ], - "main": "index.js", - "dependencies": { - "through2": "~0.2.3", - "speedometer": "~0.1.2" - }, - "devDependencies": { - "request": "~2.29.0", - "single-line-log": "~1.0.0", - "numeral": "~1.5.2" - }, - "scripts": { - "test": "node test/http.js && node test/request.js" - }, - "author": "freeall <freeall@gmail.com>", - "license": "BSD-2-Clause" -} diff --git a/node_modules/progress-stream/test/http.js b/node_modules/progress-stream/test/http.js deleted file mode 100644 index 48f3024..0000000 --- a/node_modules/progress-stream/test/http.js +++ /dev/null @@ -1,30 +0,0 @@ -var progress = require('../index'); -var http = require('http'); -var fs = require('fs'); -var log = require('single-line-log').stdout; -var numeral = require('numeral'); - -var str = progress({ - drain: true, - time: 100, - speed: 20 -}); -str.on('progress', function(progress) { - log('Running: '+numeral(progress.runtime).format('00:00:00')+' ('+numeral(progress.transferred).format('0 b')+')\n'+ - 'Left: '+numeral(progress.eta).format('00:00:00')+' ('+numeral(progress.remaining).format('0 b')+')\n'+ - numeral(progress.speed).format('0.00b')+'/s '+Math.round(progress.percentage)+'%'); -}); - -var options = { - method: 'GET', - host: 'cachefly.cachefly.net', - path: '/10mb.test', - headers: { - 'user-agent': 'testy test' - } -}; -http.request(options, function(response) { - response.pipe(str); -}).end(); - -console.log('progress-stream using http module - downloading 10 MB file'); diff --git a/node_modules/progress-stream/test/request.js b/node_modules/progress-stream/test/request.js deleted file mode 100644 index c5d676b..0000000 --- a/node_modules/progress-stream/test/request.js +++ /dev/null @@ -1,20 +0,0 @@ -var progress = require('../index'); -var req = require('request'); -var fs = require('fs'); -var log = require('single-line-log').stdout; -var numeral = require('numeral'); - -var str = progress({ - drain: true, - time: 100 -}, function(progress) { - log('Running: '+numeral(progress.runtime).format('00:00:00')+' ('+numeral(progress.transferred).format('0 b')+')\n'+ - 'Left: '+numeral(progress.eta).format('00:00:00')+' ('+numeral(progress.remaining).format('0 b')+')\n'+ - numeral(progress.speed).format('0.00b')+'/s '+Math.round(progress.percentage)+'%'); -}); - -req('http://cachefly.cachefly.net/10mb.test', { - headers: { 'user-agent': 'test' } -}).pipe(str); - -console.log('progress-stream using request module - downloading 10 MB file'); |