| FazBrowse GitHub Viewer | Trending | | Home |
| Tools: [Download Repo ZIP] [Original HTTPS Page] |
1 parent 6b36161 commit 412f380
3 files changed
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -0,0 +1,93 @@ | |||
| 1 | + 'use strict'; | ||
| 2 | + | ||
| 3 | + const EE = require('events'); | ||
| 4 | + const util = require('util'); | ||
| 5 | + | ||
| 6 | + function Stream() { | ||
| 7 | + EE.call(this); | ||
| 8 | + } | ||
| 9 | + util.inherits(Stream, EE); | ||
| 10 | + | ||
| 11 | + Stream.prototype.pipe = function(dest, options) { | ||
| 12 | + var source = this; | ||
| 13 | + | ||
| 14 | + function ondata(chunk) { | ||
| 15 | + if (dest.writable) { | ||
| 16 | + if (false === dest.write(chunk) && source.pause) { | ||
| 17 | + source.pause(); | ||
| 18 | + } | ||
| 19 | + } | ||
| 20 | + } | ||
| 21 | + | ||
| 22 | + source.on('data', ondata); | ||
| 23 | + | ||
| 24 | + function ondrain() { | ||
| 25 | + if (source.readable && source.resume) { | ||
| 26 | + source.resume(); | ||
| 27 | + } | ||
| 28 | + } | ||
| 29 | + | ||
| 30 | + dest.on('drain', ondrain); | ||
| 31 | + | ||
| 32 | + // If the 'end' option is not supplied, dest.end() will be called when | ||
| 33 | + // source gets the 'end' or 'close' events. Only dest.end() once. | ||
| 34 | + if (!dest._isStdio && (!options || options.end !== false)) { | ||
| 35 | + source.on('end', onend); | ||
| 36 | + source.on('close', onclose); | ||
| 37 | + } | ||
| 38 | + | ||
| 39 | + var didOnEnd = false; | ||
| 40 | + function onend() { | ||
| 41 | + if (didOnEnd) return; | ||
| 42 | + didOnEnd = true; | ||
| 43 | + | ||
| 44 | + dest.end(); | ||
| 45 | + } | ||
| 46 | + | ||
| 47 | + | ||
| 48 | + function onclose() { | ||
| 49 | + if (didOnEnd) return; | ||
| 50 | + didOnEnd = true; | ||
| 51 | + | ||
| 52 | + if (typeof dest.destroy === 'function') dest.destroy(); | ||
| 53 | + } | ||
| 54 | + | ||
| 55 | + // don't leave dangling pipes when there are errors. | ||
| 56 | + function onerror(er) { | ||
| 57 | + cleanup(); | ||
| 58 | + if (EE.listenerCount(this, 'error') === 0) { | ||
| 59 | + throw er; // Unhandled stream error in pipe. | ||
| 60 | + } | ||
| 61 | + } | ||
| 62 | + | ||
| 63 | + source.on('error', onerror); | ||
| 64 | + dest.on('error', onerror); | ||
| 65 | + | ||
| 66 | + // remove all the event listeners that were added. | ||
| 67 | + function cleanup() { | ||
| 68 | + source.removeListener('data', ondata); | ||
| 69 | + dest.removeListener('drain', ondrain); | ||
| 70 | + | ||
| 71 | + source.removeListener('end', onend); | ||
| 72 | + source.removeListener('close', onclose); | ||
| 73 | + | ||
| 74 | + source.removeListener('error', onerror); | ||
| 75 | + dest.removeListener('error', onerror); | ||
| 76 | + | ||
| 77 | + source.removeListener('end', cleanup); | ||
| 78 | + source.removeListener('close', cleanup); | ||
| 79 | + | ||
| 80 | + dest.removeListener('close', cleanup); | ||
| 81 | + } | ||
| 82 | + | ||
| 83 | + source.on('end', cleanup); | ||
| 84 | + source.on('close', cleanup); | ||
| 85 | + | ||
| 86 | + dest.on('close', cleanup); | ||
| 87 | + dest.emit('pipe', source); | ||
| 88 | + | ||
| 89 | + // Allow for unix-like usage: A.pipe(B).pipe(C) | ||
| 90 | + return dest; | ||
| 91 | + }; | ||
| 92 | + | ||
| 93 | + module.exports = Stream; | ||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -1,11 +1,9 @@ | |||
| 1 | 1 | 'use strict'; | |
| 2 | 2 | ||
| 3 | - module.exports = Stream; | ||
| 3 | + // Note: export Stream before Readable/Writable/Duplex/... | ||
| 4 | + // to avoid a cross-reference(require) issues | ||
| 5 | + const Stream = module.exports = require('internal/streams/legacy'); | ||
| 4 | 6 | ||
| 5 | - const EE = require('events'); | ||
| 6 | - const util = require('util'); | ||
| 7 | - | ||
| 8 | - util.inherits(Stream, EE); | ||
| 9 | 7 | Stream.Readable = require('_stream_readable'); | |
| 10 | 8 | Stream.Writable = require('_stream_writable'); | |
| 11 | 9 | Stream.Duplex = require('_stream_duplex'); | |
@@ -14,94 +12,3 @@ Stream.PassThrough = require('_stream_passthrough'); | |||
| 14 | 12 | ||
| 15 | 13 | // Backwards-compat with node 0.4.x | |
| 16 | 14 | Stream.Stream = Stream; | |
| 17 | - | ||
| 18 | - | ||
| 19 | - // old-style streams. Note that the pipe method (the only relevant | ||
| 20 | - // part of this class) is overridden in the Readable class. | ||
| 21 | - | ||
| 22 | - function Stream() { | ||
| 23 | - EE.call(this); | ||
| 24 | - } | ||
| 25 | - | ||
| 26 | - Stream.prototype.pipe = function(dest, options) { | ||
| 27 | - var source = this; | ||
| 28 | - | ||
| 29 | - function ondata(chunk) { | ||
| 30 | - if (dest.writable) { | ||
| 31 | - if (false === dest.write(chunk) && source.pause) { | ||
| 32 | - source.pause(); | ||
| 33 | - } | ||
| 34 | - } | ||
| 35 | - } | ||
| 36 | - | ||
| 37 | - source.on('data', ondata); | ||
| 38 | - | ||
| 39 | - function ondrain() { | ||
| 40 | - if (source.readable && source.resume) { | ||
| 41 | - source.resume(); | ||
| 42 | - } | ||
| 43 | - } | ||
| 44 | - | ||
| 45 | - dest.on('drain', ondrain); | ||
| 46 | - | ||
| 47 | - // If the 'end' option is not supplied, dest.end() will be called when | ||
| 48 | - // source gets the 'end' or 'close' events. Only dest.end() once. | ||
| 49 | - if (!dest._isStdio && (!options || options.end !== false)) { | ||
| 50 | - source.on('end', onend); | ||
| 51 | - source.on('close', onclose); | ||
| 52 | - } | ||
| 53 | - | ||
| 54 | - var didOnEnd = false; | ||
| 55 | - function onend() { | ||
| 56 | - if (didOnEnd) return; | ||
| 57 | - didOnEnd = true; | ||
| 58 | - | ||
| 59 | - dest.end(); | ||
| 60 | - } | ||
| 61 | - | ||
| 62 | - | ||
| 63 | - function onclose() { | ||
| 64 | - if (didOnEnd) return; | ||
| 65 | - didOnEnd = true; | ||
| 66 | - | ||
| 67 | - if (typeof dest.destroy === 'function') dest.destroy(); | ||
| 68 | - } | ||
| 69 | - | ||
| 70 | - // don't leave dangling pipes when there are errors. | ||
| 71 | - function onerror(er) { | ||
| 72 | - cleanup(); | ||
| 73 | - if (EE.listenerCount(this, 'error') === 0) { | ||
| 74 | - throw er; // Unhandled stream error in pipe. | ||
| 75 | - } | ||
| 76 | - } | ||
| 77 | - | ||
| 78 | - source.on('error', onerror); | ||
| 79 | - dest.on('error', onerror); | ||
| 80 | - | ||
| 81 | - // remove all the event listeners that were added. | ||
| 82 | - function cleanup() { | ||
| 83 | - source.removeListener('data', ondata); | ||
| 84 | - dest.removeListener('drain', ondrain); | ||
| 85 | - | ||
| 86 | - source.removeListener('end', onend); | ||
| 87 | - source.removeListener('close', onclose); | ||
| 88 | - | ||
| 89 | - source.removeListener('error', onerror); | ||
| 90 | - dest.removeListener('error', onerror); | ||
| 91 | - | ||
| 92 | - source.removeListener('end', cleanup); | ||
| 93 | - source.removeListener('close', cleanup); | ||
| 94 | - | ||
| 95 | - dest.removeListener('close', cleanup); | ||
| 96 | - } | ||
| 97 | - | ||
| 98 | - source.on('end', cleanup); | ||
| 99 | - source.on('close', cleanup); | ||
| 100 | - | ||
| 101 | - dest.on('close', cleanup); | ||
| 102 | - | ||
| 103 | - dest.emit('pipe', source); | ||
| 104 | - | ||
| 105 | - // Allow for unix-like usage: A.pipe(B).pipe(C) | ||
| 106 | - return dest; | ||
| 107 | - }; | ||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -93,6 +93,7 @@ | |||
| 93 | 93 | 'lib/internal/v8_prof_processor.js', | |
| 94 | 94 | 'lib/internal/streams/lazy_transform.js', | |
| 95 | 95 | 'lib/internal/streams/BufferList.js', | |
| 96 | + 'lib/internal/streams/legacy.js', | ||
| 96 | 97 | 'deps/v8/tools/splaytree.js', | |
| 97 | 98 | 'deps/v8/tools/codemap.js', | |
| 98 | 99 | 'deps/v8/tools/consarray.js', | |
| Back | FazBrowse Home | New Git URL |
0 commit comments