summaryrefslogtreecommitdiff
path: root/deps/npm/node_modules/readable-stream/lib/_stream_transform.js
diff options
context:
space:
mode:
Diffstat (limited to 'deps/npm/node_modules/readable-stream/lib/_stream_transform.js')
-rw-r--r--deps/npm/node_modules/readable-stream/lib/_stream_transform.js68
1 files changed, 34 insertions, 34 deletions
diff --git a/deps/npm/node_modules/readable-stream/lib/_stream_transform.js b/deps/npm/node_modules/readable-stream/lib/_stream_transform.js
index a0c23173da..5d1f8b876d 100644
--- a/deps/npm/node_modules/readable-stream/lib/_stream_transform.js
+++ b/deps/npm/node_modules/readable-stream/lib/_stream_transform.js
@@ -74,39 +74,28 @@ util.inherits = require('inherits');
util.inherits(Transform, Duplex);
-function TransformState(stream) {
- this.afterTransform = function (er, data) {
- return afterTransform(stream, er, data);
- };
-
- this.needTransform = false;
- this.transforming = false;
- this.writecb = null;
- this.writechunk = null;
- this.writeencoding = null;
-}
-
-function afterTransform(stream, er, data) {
- var ts = stream._transformState;
+function afterTransform(er, data) {
+ var ts = this._transformState;
ts.transforming = false;
var cb = ts.writecb;
if (!cb) {
- return stream.emit('error', new Error('write callback called multiple times'));
+ return this.emit('error', new Error('write callback called multiple times'));
}
ts.writechunk = null;
ts.writecb = null;
- if (data !== null && data !== undefined) stream.push(data);
+ if (data != null) // single equals check for both `null` and `undefined`
+ this.push(data);
cb(er);
- var rs = stream._readableState;
+ var rs = this._readableState;
rs.reading = false;
if (rs.needReadable || rs.length < rs.highWaterMark) {
- stream._read(rs.highWaterMark);
+ this._read(rs.highWaterMark);
}
}
@@ -115,9 +104,14 @@ function Transform(options) {
Duplex.call(this, options);
- this._transformState = new TransformState(this);
-
- var stream = this;
+ this._transformState = {
+ afterTransform: afterTransform.bind(this),
+ needTransform: false,
+ transforming: false,
+ writecb: null,
+ writechunk: null,
+ writeencoding: null
+ };
// start out asking for a readable event once data is transformed.
this._readableState.needReadable = true;
@@ -134,11 +128,19 @@ function Transform(options) {
}
// When the writable side finishes, then flush out anything remaining.
- this.once('prefinish', function () {
- if (typeof this._flush === 'function') this._flush(function (er, data) {
- done(stream, er, data);
- });else done(stream);
- });
+ this.on('prefinish', prefinish);
+}
+
+function prefinish() {
+ var _this = this;
+
+ if (typeof this._flush === 'function') {
+ this._flush(function (er, data) {
+ done(_this, er, data);
+ });
+ } else {
+ done(this, null, null);
+ }
}
Transform.prototype.push = function (chunk, encoding) {
@@ -188,27 +190,25 @@ Transform.prototype._read = function (n) {
};
Transform.prototype._destroy = function (err, cb) {
- var _this = this;
+ var _this2 = this;
Duplex.prototype._destroy.call(this, err, function (err2) {
cb(err2);
- _this.emit('close');
+ _this2.emit('close');
});
};
function done(stream, er, data) {
if (er) return stream.emit('error', er);
- if (data !== null && data !== undefined) stream.push(data);
+ if (data != null) // single equals check for both `null` and `undefined`
+ stream.push(data);
// if there's nothing in the write buffer, then that means
// that nothing more will ever be provided
- var ws = stream._writableState;
- var ts = stream._transformState;
-
- if (ws.length) throw new Error('Calling transform done when ws.length != 0');
+ if (stream._writableState.length) throw new Error('Calling transform done when ws.length != 0');
- if (ts.transforming) throw new Error('Calling transform done when still transforming');
+ if (stream._transformState.transforming) throw new Error('Calling transform done when still transforming');
return stream.push(null);
} \ No newline at end of file