(stream, startPaused)
| 3546 | }; |
| 3547 | |
| 3548 | function emitDataEvents(stream, startPaused) { |
| 3549 | var state = stream._readableState; |
| 3550 | |
| 3551 | if (state.flowing) { |
| 3552 | // https://github.com/isaacs/readable-stream/issues/16 |
| 3553 | throw new Error('Cannot switch to old mode now.'); |
| 3554 | } |
| 3555 | |
| 3556 | var paused = startPaused || false; |
| 3557 | var readable = false; |
| 3558 | |
| 3559 | // convert to an old-style stream. |
| 3560 | stream.readable = true; |
| 3561 | stream.pipe = Stream.prototype.pipe; |
| 3562 | stream.on = stream.addListener = Stream.prototype.on; |
| 3563 | |
| 3564 | stream.on('readable', function() { |
| 3565 | readable = true; |
| 3566 | |
| 3567 | var c; |
| 3568 | while (!paused && (null !== (c = stream.read()))) |
| 3569 | stream.emit('data', c); |
| 3570 | |
| 3571 | if (c === null) { |
| 3572 | readable = false; |
| 3573 | stream._readableState.needReadable = true; |
| 3574 | } |
| 3575 | }); |
| 3576 | |
| 3577 | stream.pause = function() { |
| 3578 | paused = true; |
| 3579 | this.emit('pause'); |
| 3580 | }; |
| 3581 | |
| 3582 | stream.resume = function() { |
| 3583 | paused = false; |
| 3584 | if (readable) |
| 3585 | process.nextTick(function() { |
| 3586 | stream.emit('readable'); |
| 3587 | }); |
| 3588 | else |
| 3589 | this.read(0); |
| 3590 | this.emit('resume'); |
| 3591 | }; |
| 3592 | |
| 3593 | // now make it start, just in case it hadn't already. |
| 3594 | stream.emit('readable'); |
| 3595 | } |
| 3596 | |
| 3597 | // wrap an old-style stream as the async data source. |
| 3598 | // This is *not* part of the readable stream interface. |
no test coverage detected