From f91b047891c0deb402220b385f166c08edcb0591 Mon Sep 17 00:00:00 2001 From: Julian Gruber Date: Mon, 19 Aug 2013 13:14:42 -0400 Subject: [PATCH] stream: make setEncoding chainable --- lib/_stream_readable.js | 1 + test/simple/test-stream2-set-encoding.js | 6 ++++++ 2 files changed, 7 insertions(+) diff --git a/lib/_stream_readable.js b/lib/_stream_readable.js index 6dadc28..450b506 100644 --- a/lib/_stream_readable.js +++ b/lib/_stream_readable.js @@ -198,6 +198,7 @@ Readable.prototype.setEncoding = function(enc) { StringDecoder = require('string_decoder').StringDecoder; this._readableState.decoder = new StringDecoder(enc); this._readableState.encoding = enc; + return this; }; // Don't raise the hwm > 128MB diff --git a/test/simple/test-stream2-set-encoding.js b/test/simple/test-stream2-set-encoding.js index 5d2c32a..9b28e55 100644 --- a/test/simple/test-stream2-set-encoding.js +++ b/test/simple/test-stream2-set-encoding.js @@ -359,3 +359,9 @@ test('encoding: base64', function(t) { t.end(); }); }); + +test('chainable', function(t) { + var tr = new TestReader(100); + t.equal(tr.setEncoding('utf8'), tr); + t.end(); +}); -- 2.7.4