summaryrefslogtreecommitdiff
path: root/lib/_stream_transform.js
diff options
context:
space:
mode:
authorisaacs <i@izs.me>2012-10-04 16:58:43 -0700
committerisaacs <i@izs.me>2012-12-13 17:00:25 -0800
commitcaa853bb06c9ef1ba4203a42ad9e1072c3988a38 (patch)
treeb649b5da8e40a442316d92bd85398af3ba24af45 /lib/_stream_transform.js
parent3b59fd70f4ef26742cc66a28105d2be75590e4d2 (diff)
downloadandroid-node-v8-caa853bb06c9ef1ba4203a42ad9e1072c3988a38.tar.gz
android-node-v8-caa853bb06c9ef1ba4203a42ad9e1072c3988a38.tar.bz2
android-node-v8-caa853bb06c9ef1ba4203a42ad9e1072c3988a38.zip
transform: Automatically read() on _write when read buffer is empty
Diffstat (limited to 'lib/_stream_transform.js')
-rw-r--r--lib/_stream_transform.js16
1 files changed, 15 insertions, 1 deletions
diff --git a/lib/_stream_transform.js b/lib/_stream_transform.js
index a3603f42a6..40917de7ab 100644
--- a/lib/_stream_transform.js
+++ b/lib/_stream_transform.js
@@ -110,14 +110,28 @@ Transform.prototype._transform = function(chunk, output, cb) {
Transform.prototype._write = function(chunk, cb) {
var ts = this._transformState;
+ var rs = this._readableState;
ts.buffer.push([chunk, cb]);
+ // no need for auto-pull if already in the midst of one.
+ if (ts.transforming)
+ return;
+
// now we have something to transform, if we were waiting for it.
- if (ts.pendingReadCb && !ts.transforming) {
+ // kick off a _read to pull it in.
+ if (ts.pendingReadCb) {
var readcb = ts.pendingReadCb;
ts.pendingReadCb = null;
this._read(-1, readcb);
}
+
+ // if we weren't waiting for it, but nothing is queued up, then
+ // still kick off a transform, just so it's there when the user asks.
+ if (rs.length === 0) {
+ var ret = this.read();
+ if (ret !== null)
+ return cb(new Error('invalid stream transform state'));
+ }
};
Transform.prototype._read = function(n, readcb) {