| FazBrowse GitHub Viewer | Trending | | Home |
| Tools: [Download Repo ZIP] [Original HTTPS Page] |
1 parent decfc2a commit 8a10916
2 files changed
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -66,7 +66,6 @@ ObjectSetPrototypeOf(Readable.prototype, Stream.prototype); | |||
| 66 | 66 | ObjectSetPrototypeOf(Readable, Stream); | |
| 67 | 67 | ||
| 68 | 68 | const { errorOrDestroy } = destroyImpl; | |
| 69 | - const kProxyEvents = ['error', 'close', 'destroy', 'pause', 'resume']; | ||
| 70 | 69 | ||
| 71 | 70 | function prependListener(emitter, event, fn) { | |
| 72 | 71 | // Sadly this is not cacheable as some libraries bundle their own | |
@@ -1055,10 +1054,29 @@ Readable.prototype.wrap = function(stream) { | |||
| 1055 | 1054 | } | |
| 1056 | 1055 | } | |
| 1057 | 1056 | ||
| 1058 | - // Proxy certain important events. | ||
| 1059 | - for (const kProxyEvent of kProxyEvents) { | ||
| 1060 | - stream.on(kProxyEvent, this.emit.bind(this, kProxyEvent)); | ||
| 1061 | - } | ||
| 1057 | + stream.on('error', (err) => { | ||
| 1058 | + errorOrDestroy(this, err); | ||
| 1059 | + }); | ||
| 1060 | + | ||
| 1061 | + stream.on('close', () => { | ||
| 1062 | + // TODO(ronag): Update readable state? | ||
| 1063 | + this.emit('close'); | ||
| 1064 | + }); | ||
| 1065 | + | ||
| 1066 | + stream.on('destroy', () => { | ||
| 1067 | + // TODO(ronag): this.destroy()? | ||
| 1068 | + this.emit('destroy'); | ||
| 1069 | + }); | ||
| 1070 | + | ||
| 1071 | + stream.on('pause', () => { | ||
| 1072 | + // TODO(ronag): this.pause()? | ||
| 1073 | + this.emit('pause'); | ||
| 1074 | + }); | ||
| 1075 | + | ||
| 1076 | + stream.on('resume', () => { | ||
| 1077 | + // TODO(ronag): this.resume()? | ||
| 1078 | + this.emit('resume'); | ||
| 1079 | + }); | ||
| 1062 | 1080 | ||
| 1063 | 1081 | // When we try to consume some more bytes, simply unpause the | |
| 1064 | 1082 | // underlying stream. | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -0,0 +1,31 @@ | |||
| 1 | + 'use strict'; | ||
| 2 | + const common = require('../common'); | ||
| 3 | + const assert = require('assert'); | ||
| 4 | + | ||
| 5 | + const Readable = require('_stream_readable'); | ||
| 6 | + const EE = require('events').EventEmitter; | ||
| 7 | + | ||
| 8 | + class LegacyStream extends EE { | ||
| 9 | + pause() {} | ||
| 10 | + resume() {} | ||
| 11 | + } | ||
| 12 | + | ||
| 13 | + { | ||
| 14 | + const oldStream = new LegacyStream(); | ||
| 15 | + const r = new Readable({ autoDestroy: true }) | ||
| 16 | + .wrap(oldStream) | ||
| 17 | + .on('error', common.mustCall(() => { | ||
| 18 | + assert.strictEqual(r.destroyed, true); | ||
| 19 | + })); | ||
| 20 | + oldStream.emit('error', new Error()); | ||
| 21 | + } | ||
| 22 | + | ||
| 23 | + { | ||
| 24 | + const oldStream = new LegacyStream(); | ||
| 25 | + const r = new Readable({ autoDestroy: false }) | ||
| 26 | + .wrap(oldStream) | ||
| 27 | + .on('error', common.mustCall(() => { | ||
| 28 | + assert.strictEqual(r.destroyed, false); | ||
| 29 | + })); | ||
| 30 | + oldStream.emit('error', new Error()); | ||
| 31 | + } | ||
| Back | FazBrowse Home | New Git URL |
0 commit comments