Skip to content
This repository has been archived by the owner on Oct 5, 2022. It is now read-only.

Commit

Permalink
Major reworking of streams
Browse files Browse the repository at this point in the history
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 <[email protected]>
  • Loading branch information
kevinoid committed Apr 13, 2013
1 parent 338e07e commit 9415d5d
Show file tree
Hide file tree
Showing 4 changed files with 42 additions and 37 deletions.
2 changes: 1 addition & 1 deletion repl.js
Original file line number Diff line number Diff line change
Expand Up @@ -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) {};
Expand Down
73 changes: 39 additions & 34 deletions stream.js
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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) {};
Expand All @@ -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) {};
Expand All @@ -159,54 +159,52 @@ 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) {};

/**
* @constructor
* @param {Object=} options
* @extends stream.Readable
* @implements stream.Writable
* Xextends stream.Writable
*/
stream.Duplex = function(options) {};

Expand All @@ -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
Expand Down
2 changes: 1 addition & 1 deletion tls.js
Original file line number Diff line number Diff line change
Expand Up @@ -115,7 +115,7 @@ tls.Server.prototype.connections;

/**
* @constructor
* @extends stream
* @extends stream.Duplex
*/
tls.CleartextStream = function() {};

Expand Down
2 changes: 1 addition & 1 deletion zlib.js
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ zlib.Options;

/**
* @constructor
* @extends stream.WriteStream
* @extends stream.Transform
*/
zlib.Zlib = function() {};

Expand Down

0 comments on commit 9415d5d

Please sign in to comment.