| 3880 | |
| 3881 | |
| 3882 | function Transform(options) { |
| 3883 | if (!(this instanceof Transform)) |
| 3884 | return new Transform(options); |
| 3885 | |
| 3886 | Duplex.call(this, options); |
| 3887 | |
| 3888 | var ts = this._transformState = new TransformState(options, this); |
| 3889 | |
| 3890 | // when the writable side finishes, then flush out anything remaining. |
| 3891 | var stream = this; |
| 3892 | |
| 3893 | // start out asking for a readable event once data is transformed. |
| 3894 | this._readableState.needReadable = true; |
| 3895 | |
| 3896 | // we have implemented the _read method, and done the other things |
| 3897 | // that Readable wants before the first _read call, so unset the |
| 3898 | // sync guard flag. |
| 3899 | this._readableState.sync = false; |
| 3900 | |
| 3901 | this.once('finish', function() { |
| 3902 | if ('function' === typeof this._flush) |
| 3903 | this._flush(function(er) { |
| 3904 | done(stream, er); |
| 3905 | }); |
| 3906 | else |
| 3907 | done(stream); |
| 3908 | }); |
| 3909 | } |
| 3910 | |
| 3911 | Transform.prototype.push = function(chunk, encoding) { |
| 3912 | this._transformState.needTransform = false; |