summaryrefslogtreecommitdiff
path: root/node_modules/progress-stream
diff options
context:
space:
mode:
authorArman Shah <[email protected]>2018-02-19 23:50:04 -0800
committerArman Shah <[email protected]>2018-02-19 23:50:04 -0800
commitae34dcfd3823a609ba7182f2d6eda593be876f7d (patch)
treeb9d7f2884c4999349418cbdc4f9ab46d113e0afd /node_modules/progress-stream
parentInitial commit (diff)
downloadlauncher-ae34dcfd3823a609ba7182f2d6eda593be876f7d.tar.xz
launcher-ae34dcfd3823a609ba7182f2d6eda593be876f7d.zip
add base files
Diffstat (limited to 'node_modules/progress-stream')
-rw-r--r--node_modules/progress-stream/.npmignore2
-rw-r--r--node_modules/progress-stream/LICENSE23
-rw-r--r--node_modules/progress-stream/README.md163
-rw-r--r--node_modules/progress-stream/index.js98
-rw-r--r--node_modules/progress-stream/package.json68
-rw-r--r--node_modules/progress-stream/test/http.js30
-rw-r--r--node_modules/progress-stream/test/request.js20
7 files changed, 404 insertions, 0 deletions
diff --git a/node_modules/progress-stream/.npmignore b/node_modules/progress-stream/.npmignore
new file mode 100644
index 0000000..fd4f2b0
--- /dev/null
+++ b/node_modules/progress-stream/.npmignore
@@ -0,0 +1,2 @@
+node_modules
+.DS_Store
diff --git a/node_modules/progress-stream/LICENSE b/node_modules/progress-stream/LICENSE
new file mode 100644
index 0000000..1207b39
--- /dev/null
+++ b/node_modules/progress-stream/LICENSE
@@ -0,0 +1,23 @@
+Copyright (c) Tobias Baunbæk <[email protected]>
+
+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
new file mode 100644
index 0000000..85ca574
--- /dev/null
+++ b/node_modules/progress-stream/README.md
@@ -0,0 +1,163 @@
+# 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
new file mode 100644
index 0000000..5036935
--- /dev/null
+++ b/node_modules/progress-stream/index.js
@@ -0,0 +1,98 @@
+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
new file mode 100644
index 0000000..878fa22
--- /dev/null
+++ b/node_modules/progress-stream/package.json
@@ -0,0 +1,68 @@
+{
+ "_from": "progress-stream@^1.1.0",
+ "_id": "[email protected]",
+ "_inBundle": false,
+ "_integrity": "sha1-LNPP6jO6OonJwSHsM0er6asSX3c=",
+ "_location": "/progress-stream",
+ "_phantomChildren": {},
+ "_requested": {
+ "type": "range",
+ "registry": true,
+ "raw": "progress-stream@^1.1.0",
+ "name": "progress-stream",
+ "escapedName": "progress-stream",
+ "rawSpec": "^1.1.0",
+ "saveSpec": null,
+ "fetchSpec": "^1.1.0"
+ },
+ "_requiredBy": [
+ "/nugget"
+ ],
+ "_resolved": "https://registry.npmjs.org/progress-stream/-/progress-stream-1.2.0.tgz",
+ "_shasum": "2cd3cfea33ba3a89c9c121ec3347abe9ab125f77",
+ "_spec": "progress-stream@^1.1.0",
+ "_where": "/Users/armanshah/Desktop/node-projects/shopping-list/node_modules/nugget",
+ "author": {
+ "name": "freeall",
+ "email": "[email protected]"
+ },
+ "bugs": {
+ "url": "https://github.com/freeall/progress-stream/issues"
+ },
+ "bundleDependencies": false,
+ "dependencies": {
+ "speedometer": "~0.1.2",
+ "through2": "~0.2.3"
+ },
+ "deprecated": false,
+ "description": "Read the progress of a stream",
+ "devDependencies": {
+ "numeral": "~1.5.2",
+ "request": "~2.29.0",
+ "single-line-log": "~1.0.0"
+ },
+ "homepage": "https://github.com/freeall/progress-stream#readme",
+ "keywords": [
+ "stream",
+ "progress",
+ "percentage",
+ "percent",
+ "download",
+ "upload",
+ "file",
+ "streaming",
+ "request",
+ "http"
+ ],
+ "license": "BSD-2-Clause",
+ "main": "index.js",
+ "name": "progress-stream",
+ "repository": {
+ "type": "git",
+ "url": "git+ssh://[email protected]/freeall/progress-stream.git"
+ },
+ "scripts": {
+ "test": "node test/http.js && node test/request.js"
+ },
+ "version": "1.2.0"
+}
diff --git a/node_modules/progress-stream/test/http.js b/node_modules/progress-stream/test/http.js
new file mode 100644
index 0000000..48f3024
--- /dev/null
+++ b/node_modules/progress-stream/test/http.js
@@ -0,0 +1,30 @@
+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
new file mode 100644
index 0000000..c5d676b
--- /dev/null
+++ b/node_modules/progress-stream/test/request.js
@@ -0,0 +1,20 @@
+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');