Comparing version 0.1.0 to 1.0.0
@@ -8,3 +8,8 @@ /* | ||
var mod_tty = require('tty'); | ||
var mod_stream = require('stream'); | ||
if (!mod_stream.Transform) { | ||
mod_stream = require('readable-stream'); | ||
} | ||
var mod_assert = require('assert-plus'); | ||
@@ -245,4 +250,4 @@ var mod_sprintf = require('sprintf'); | ||
'options.maxdrawfreq > 0'); | ||
self.pb_drawperiod = Math.floor((1 / options.maxdrawfreq) | ||
* 1000); | ||
self.pb_drawperiod = Math.floor((1 / options.maxdrawfreq) * | ||
1000); | ||
} else { | ||
@@ -253,4 +258,6 @@ self.pb_drawperiod = 500; /* 2 Hz */ | ||
self.pb_lastdrawwidth = 0; | ||
self.pb_startat = +Date.now(); | ||
self.pb_startat = Date.now(); | ||
self.pb_readings = 0; | ||
self.pb_stream = null; | ||
} | ||
@@ -335,2 +342,56 @@ | ||
ProgressBar.prototype.stream = function | ||
stream(stream_opts) | ||
{ | ||
var self = this; | ||
if (self.pb_stream === null) { | ||
if (!stream_opts) { | ||
/* | ||
* If the user does not pass in stream options, | ||
* create a basic options field without any buffering. | ||
*/ | ||
stream_opts = { | ||
highWaterMark: 0 | ||
}; | ||
} | ||
/* | ||
* Detect if the user requested an Object Mode stream or not. | ||
*/ | ||
var was_object_mode = false; | ||
if (stream_opts.objectMode) { | ||
was_object_mode = true; | ||
} | ||
self.pb_stream = new mod_stream.Transform(stream_opts); | ||
self.pb_stream._transform = function (data, _, done) { | ||
this.push(data); | ||
if (was_object_mode) { | ||
/* | ||
* Each _transform() call represents one | ||
* object in the stream. | ||
*/ | ||
self.advance(1); | ||
} else { | ||
/* | ||
* Each _transform() call should receive | ||
* either a Buffer or a String, both of | ||
* which ought to have a numeric length | ||
* property. | ||
*/ | ||
mod_assert.number(data.length, 'data.length'); | ||
self.advance(data.length); | ||
} | ||
done(); | ||
}; | ||
self.pb_stream._flush = function (done) { | ||
self.end(); | ||
done(); | ||
}; | ||
} | ||
return (self.pb_stream); | ||
}; | ||
ProgressBar.prototype.end = function | ||
@@ -381,3 +442,3 @@ end() | ||
self.advance(0); | ||
} | ||
}; | ||
@@ -403,3 +464,3 @@ ProgressBar.prototype.advance = function | ||
var now = +Date.now(); | ||
var now = Date.now(); | ||
if (now - self.pb_lastdrawtime > self.pb_drawperiod) | ||
@@ -426,3 +487,3 @@ self.draw(); | ||
var etastr = ''; | ||
var now = +Date.now(); | ||
var now = Date.now(); | ||
if ((self.pb_nosize || self.pb_size > 0) && self.pb_readings > 5 && | ||
@@ -477,3 +538,3 @@ (now - self.pb_startat) > WARMUP_DELAY) { | ||
self.pb_lastdrawwidth = filestr.length + bar.length + infostr.length; | ||
self.pb_lastdrawtime = +Date.now(); | ||
self.pb_lastdrawtime = Date.now(); | ||
}; | ||
@@ -480,0 +541,0 @@ |
{ | ||
"name": "progbar", | ||
"author": "Joshua M. Clulow <jmc@joyent.com>", | ||
"version": "0.1.0", | ||
"version": "1.0.0", | ||
"description": "terminal progress bar", | ||
@@ -15,3 +15,4 @@ "main": "./lib/progbar.js", | ||
"assert-plus": "~0.1.5", | ||
"sprintf": "~0.1.3" | ||
"sprintf": "~0.1.3", | ||
"readable-stream": "~1.0.27-1" | ||
}, | ||
@@ -18,0 +19,0 @@ |
@@ -35,2 +35,10 @@ # node-progbar | ||
}); | ||
/* | ||
* You may also use the stream() method to get a passthrough stream | ||
* that you may pipe your data through. The bar will advance with | ||
* the passage of bytes through the stream, and end() will be called | ||
* at the end of the stream. | ||
*/ | ||
input_stream.pipe(bar.stream()).pipe(output_stream); | ||
``` |
No v1
QualityPackage is not semver >=1. This means it is not stable and does not support ^ ranges.
Found 1 instance in 1 package
16839
8
537
1
44
3
+ Addedreadable-stream@~1.0.27-1
+ Addedcore-util-is@1.0.3(transitive)
+ Addedinherits@2.0.4(transitive)
+ Addedisarray@0.0.1(transitive)
+ Addedreadable-stream@1.0.34(transitive)
+ Addedstring_decoder@0.10.31(transitive)