aboutsummaryrefslogtreecommitdiff
path: root/lib/_stream_readable.js
diff options
context:
space:
mode:
authorJackson Tian <shyvo1987@gmail.com>2015-12-18 11:29:08 +0800
committerJames M Snell <jasnell@gmail.com>2016-01-14 17:34:29 -0800
commitbfb2cd0bfddd716366f1c89637cca9fc1234e592 (patch)
tree66358fa634231f78cff3d2f28634579985163611 /lib/_stream_readable.js
parentebd9addcd11034b7415e937c1c49857a1f61395b (diff)
downloadandroid-node-v8-bfb2cd0bfddd716366f1c89637cca9fc1234e592.tar.gz
android-node-v8-bfb2cd0bfddd716366f1c89637cca9fc1234e592.tar.bz2
android-node-v8-bfb2cd0bfddd716366f1c89637cca9fc1234e592.zip
stream: add bytesRead property for readable
Add a bytesRead property for readable is useful in some use cases. When user want know how many bytes read of readable, need to caculate it in userland. If encoding is specificed, get the value is very slowly. PR-URL: https://github.com/nodejs/node/pull/4372 Reviewed-By: Trevor Norris <trev.norris@gmail.com> Reviewed-By: Colin Ihrig <cjihrig@gmail.com> Reviewed-By: James M Snell <jasnell@gmail.com>
Diffstat (limited to 'lib/_stream_readable.js')
-rw-r--r--lib/_stream_readable.js3
1 files changed, 3 insertions, 0 deletions
diff --git a/lib/_stream_readable.js b/lib/_stream_readable.js
index bdc263d6ef..8cad1f1a37 100644
--- a/lib/_stream_readable.js
+++ b/lib/_stream_readable.js
@@ -83,6 +83,8 @@ function Readable(options) {
this._readableState = new ReadableState(options, this);
+ this.bytesRead = 0;
+
// legacy
this.readable = true;
@@ -135,6 +137,7 @@ function readableAddChunk(stream, state, chunk, encoding, addToFront) {
var e = new Error('stream.unshift() after end event');
stream.emit('error', e);
} else {
+ stream.bytesRead += state.objectMode ? 0 : chunk.length;
if (state.decoder && !addToFront && !encoding)
chunk = state.decoder.write(chunk);