From 9415d5d2f26b8d61a61f676cedaef4f12a348edb Mon Sep 17 00:00:00 2001 From: Kevin Locke Date: Sat, 13 Apr 2013 11:13:12 -0600 Subject: [PATCH] Major reworking of streams Update the annotations to match their definitions in node 0.10. Also, stream (the namespace) is not a class, use stream.Stream instead as appropriate. This commit doesn't fix the multiple inheritance/mixin issue with Duplex needing to extend from both Readable and Writable. This may require defining some interfaces which can be implemented. This commit also doesn't touch ReadableStream and WritableStream. I'm not sure of the purpose of these classes and since they are heavily used in other namespaces, I'll leave them alone for now. Signed-off-by: Kevin Locke --- repl.js | 2 +- stream.js | 73 +++++++++++++++++++++++++++++-------------------------- tls.js | 2 +- zlib.js | 2 +- 4 files changed, 42 insertions(+), 37 deletions(-) diff --git a/repl.js b/repl.js index b7864b7..02f0bc6 100644 --- a/repl.js +++ b/repl.js @@ -34,7 +34,7 @@ var repl = {}; /** - * @param {{prompt: ?string, input: ?stream, output: ?stream, terminal: ?boolean, eval: ?function(string), useColors: ?boolean, useGlobal: ?boolean, ignoreUndefined: ?boolean, writer: ?function(string)}} options + * @param {{prompt: ?string, input: ?stream.Readable, output: ?stream.Writable, terminal: ?boolean, eval: ?function(string), useColors: ?boolean, useGlobal: ?boolean, ignoreUndefined: ?boolean, writer: ?function(string)}} options * @return {repl.REPLServer} */ repl.start = function(options) {}; diff --git a/stream.js b/stream.js index 27ee8d1..b543cbd 100644 --- a/stream.js +++ b/stream.js @@ -28,16 +28,21 @@ END_NODE_INCLUDE */ +var stream = {}; + /** * @constructor + * @param {Object=} options * @extends events.EventEmitter */ -var stream = function() {}; +stream.Stream = function(options) {}; /** - * @type {stream} + * @param {stream.Writable} dest + * @param {{end: boolean}=} pipeOpts + * @return {stream.Writable} */ -stream.Stream = function() {}; +stream.Stream.prototype.pipe = function(dest, pipeOpts) {}; /** * @constructor @@ -99,23 +104,25 @@ stream.WritableStream.prototype.destroySoon = function() {}; /** * @constructor * @param {Object=} options - * @extends stream + * @extends stream.Stream */ stream.Readable = function(options) {}; /** * @type {boolean} + * @deprecated */ stream.Readable.prototype.readable; /** - * @param {string|buffer.Buffer} chunk + * @protected + * @param {string|buffer.Buffer|null} chunk * @return {boolean} */ stream.Readable.prototype.push = function(chunk) {}; /** - * @param {string|buffer.Buffer} chunk + * @param {string|buffer.Buffer|null} chunk * @return {boolean} */ stream.Readable.prototype.unshift = function(chunk) {}; @@ -126,26 +133,19 @@ stream.Readable.prototype.unshift = function(chunk) {}; stream.Readable.prototype.setEncoding = function(enc) {}; /** - * @param {number} n - * @return {buffer.Buffer} + * @param {number=} n + * @return {buffer.Buffer|string|null} */ stream.Readable.prototype.read = function(n) {}; /** + * @protected * @param {number} n - * @return {?buffer.Buffer} */ stream.Readable.prototype._read = function(n) {}; /** - * @param {stream.Writable} dest - * @param {{end: boolean}=} pipeOpts - * @return {stream.Writable} - */ -stream.Readable.prototype.pipe = function(dest, pipeOpts) {}; - -/** - * @param {stream.Writable} dest + * @param {stream.Writable=} dest * @return {stream.Readable} */ stream.Readable.prototype.unpipe = function(dest) {}; @@ -159,46 +159,44 @@ stream.Readable.prototype.resume = function() {}; stream.Readable.prototype.pause = function() {}; /** - * @param {stream} stream + * @param {stream.Stream} stream + * @return {stream.Readable} */ stream.Readable.prototype.wrap = function(stream) {}; /** * @constructor * @param {Object=} options - * @extends stream + * @extends stream.Stream */ stream.Writable = function(options) {}; /** + * @deprecated * @type {boolean} */ stream.Writable.prototype.writable; -/** - */ -stream.Writable.prototype.pipe = function() {}; - /** * @param {string|buffer.Buffer} chunk - * @param {(string|function(...))=} encoding - * @param {function(...)=} cb + * @param {string=} encoding + * @param {function(*=)=} cb * @return {boolean} */ stream.Writable.prototype.write = function(chunk, encoding, cb) {}; /** + * @protected * @param {string|buffer.Buffer} chunk - * @param {(string|function(...))=} encoding - * @param {function(...)=} cb + * @param {string} encoding + * @param {function(*=)} cb */ stream.Writable.prototype._write = function(chunk, encoding, cb) {}; /** - * @param {string|buffer.Buffer} chunk - * @param {(string|function(...))=} encoding - * @param {function(...)=} cb - * @return {boolean} + * @param {string|buffer.Buffer=} chunk + * @param {string=} encoding + * @param {function(*=)=} cb */ stream.Writable.prototype.end = function(chunk, encoding, cb) {}; @@ -206,7 +204,7 @@ stream.Writable.prototype.end = function(chunk, encoding, cb) {}; * @constructor * @param {Object=} options * @extends stream.Readable - * @implements stream.Writable + * Xextends stream.Writable */ stream.Duplex = function(options) {}; @@ -224,11 +222,18 @@ stream.Duplex.prototype.allowHalfOpen; stream.Transform = function(options) {}; /** + * @protected * @param {string|buffer.Buffer} chunk - * @param {*} output + * @param {string} encoding + * @param {function(*=)} cb + */ +stream.Transform._transform = function(chunk, encoding, cb) {}; + +/** + * @protected * @param {function(*=)} cb */ -stream.Transform._transform = function(chunk, output, cb) {}; +stream.Transform._flush = function(cb) {}; /** * @param {Object=} options diff --git a/tls.js b/tls.js index 5d181a2..56450f7 100644 --- a/tls.js +++ b/tls.js @@ -115,7 +115,7 @@ tls.Server.prototype.connections; /** * @constructor - * @extends stream + * @extends stream.Duplex */ tls.CleartextStream = function() {}; diff --git a/zlib.js b/zlib.js index 37591ee..30b95b7 100644 --- a/zlib.js +++ b/zlib.js @@ -42,7 +42,7 @@ zlib.Options; /** * @constructor - * @extends stream.WriteStream + * @extends stream.Transform */ zlib.Zlib = function() {};