progress-stream
Advanced tools
Comparing version 0.4.0 to 0.5.0
@@ -60,2 +60,8 @@ var through = require('through2'); | ||
}; | ||
// 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) { | ||
@@ -62,0 +68,0 @@ // Support http module |
{ | ||
"name": "progress-stream", | ||
"version": "0.4.0", | ||
"version": "0.5.0", | ||
"description": "Read the progress of a stream", | ||
@@ -5,0 +5,0 @@ "repository": { |
@@ -144,1 +144,17 @@ # progress-stream | ||
## 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); | ||
}); | ||
``` |
8339
122
160