diff --git a/doc/api/stream.markdown b/doc/api/stream.markdown index 881b33808af..1ee834f867c 100644 --- a/doc/api/stream.markdown +++ b/doc/api/stream.markdown @@ -244,6 +244,7 @@ emission of a [`'data'` event][]. #### readable.setEncoding(encoding) * `encoding` {String} The encoding to use. +* Return: `this` Call this function to cause the stream to return strings of the specified encoding instead of Buffer objects. For example, if you do @@ -268,6 +269,8 @@ readable.on('data', function(chunk) { #### readable.resume() +* Return: `this` + This method will cause the readable stream to resume emitting `data` events. @@ -286,6 +289,8 @@ readable.on('end', function(chunk) { #### readable.pause() +* Return: `this` + This method will cause a stream in flowing mode to stop emitting `data` events, switching out of flowing mode. Any data that becomes available will remain in the internal buffer. diff --git a/lib/_debugger.js b/lib/_debugger.js index aca52e5f300..e67d0102609 100644 --- a/lib/_debugger.js +++ b/lib/_debugger.js @@ -855,13 +855,14 @@ function Interface(stdin, stdout, args) { Interface.prototype.pause = function() { - if (this.killed || this.paused++ > 0) return false; + if (this.killed || this.paused++ > 0) return this; this.repl.rli.pause(); this.stdin.pause(); + return this; }; Interface.prototype.resume = function(silent) { - if (this.killed || this.paused === 0 || --this.paused !== 0) return false; + if (this.killed || this.paused === 0 || --this.paused !== 0) return this; this.repl.rli.resume(); if (silent !== true) { this.repl.displayPrompt(); @@ -872,6 +873,7 @@ Interface.prototype.resume = function(silent) { this.waiting(); this.waiting = null; } + return this; }; diff --git a/lib/_stream_readable.js b/lib/_stream_readable.js index 450b5065857..e1636c85a27 100644 --- a/lib/_stream_readable.js +++ b/lib/_stream_readable.js @@ -705,6 +705,7 @@ Readable.prototype.resume = function() { } resume(this, state); } + return this; }; function resume(stream, state) { @@ -731,6 +732,7 @@ Readable.prototype.pause = function() { this._readableState.flowing = false; this.emit('pause'); } + return this; }; function flow(stream) { diff --git a/lib/readline.js b/lib/readline.js index 8b5ad99efca..e45fdeac794 100644 --- a/lib/readline.js +++ b/lib/readline.js @@ -268,6 +268,7 @@ Interface.prototype.pause = function() { this.input.pause(); this.paused = true; this.emit('pause'); + return this; }; @@ -276,6 +277,7 @@ Interface.prototype.resume = function() { this.input.resume(); this.paused = false; this.emit('resume'); + return this; }; diff --git a/test/simple/test-stream2-basic.js b/test/simple/test-stream2-basic.js index 3814bf07b46..f210c9f0309 100644 --- a/test/simple/test-stream2-basic.js +++ b/test/simple/test-stream2-basic.js @@ -473,3 +473,11 @@ test('adding readable triggers data flow', function(t) { t.end(); }); }); + +test('chainable', function(t) { + var r = new R(); + r._read = function() {}; + var r2 = r.setEncoding('utf8').pause().resume().pause(); + t.equal(r, r2); + t.end(); +});