| 7039 | } |
| 7040 | |
| 7041 | function Transform(options) { |
| 7042 | if (!(this instanceof Transform)) return new Transform(options); |
| 7043 | |
| 7044 | Duplex.call(this, options); |
| 7045 | |
| 7046 | this._transformState = new TransformState(this); |
| 7047 | |
| 7048 | // when the writable side finishes, then flush out anything remaining. |
| 7049 | var stream = this; |
| 7050 | |
| 7051 | // start out asking for a readable event once data is transformed. |
| 7052 | this._readableState.needReadable = true; |
| 7053 | |
| 7054 | // we have implemented the _read method, and done the other things |
| 7055 | // that Readable wants before the first _read call, so unset the |
| 7056 | // sync guard flag. |
| 7057 | this._readableState.sync = false; |
| 7058 | |
| 7059 | if (options) { |
| 7060 | if (typeof options.transform === 'function') this._transform = options.transform; |
| 7061 | |
| 7062 | if (typeof options.flush === 'function') this._flush = options.flush; |
| 7063 | } |
| 7064 | |
| 7065 | this.once('prefinish', function () { |
| 7066 | if (typeof this._flush === 'function') this._flush(function (er) { |
| 7067 | done(stream, er); |
| 7068 | });else done(stream); |
| 7069 | }); |
| 7070 | } |
| 7071 | |
| 7072 | Transform.prototype.push = function (chunk, encoding) { |
| 7073 | this._transformState.needTransform = false; |