* A nodejs stream using a worker as source. * @see the SourceWrapper in http://nodejs.org/api/stream.html * @constructor * @param {StreamHelper} helper the helper wrapping the worker * @param {Object} options the nodejs stream options * @param {Function} updateCb the update callback.
(helper, options, updateCb)
| 14 | * @param {Function} updateCb the update callback. |
| 15 | */ |
| 16 | function NodejsStreamOutputAdapter(helper, options, updateCb) { |
| 17 | Readable.call(this, options); |
| 18 | this._helper = helper; |
| 19 | |
| 20 | var self = this; |
| 21 | helper.on("data", function (data, meta) { |
| 22 | if (!self.push(data)) { |
| 23 | self._helper.pause(); |
| 24 | } |
| 25 | if(updateCb) { |
| 26 | updateCb(meta); |
| 27 | } |
| 28 | }) |
| 29 | .on("error", function(e) { |
| 30 | self.emit("error", e); |
| 31 | }) |
| 32 | .on("end", function () { |
| 33 | self.push(null); |
| 34 | }); |
| 35 | } |
| 36 | |
| 37 | |
| 38 | NodejsStreamOutputAdapter.prototype._read = function() { |