Skip to content

Commit

Permalink
f
Browse files Browse the repository at this point in the history
  • Loading branch information
killagu committed May 2, 2018
1 parent 1ac8dc7 commit 72ebad2
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 1 deletion.
2 changes: 1 addition & 1 deletion lib/_stream_readable.js
Original file line number Diff line number Diff line change
Expand Up @@ -327,7 +327,7 @@ Readable.prototype.setEncoding = function(enc) {
if (!StringDecoder)
StringDecoder = require('string_decoder').StringDecoder;
this._readableState.decoder = new StringDecoder(enc);
// if setEncoding(null), decoder.encoding = 'utf8'
// if setEncoding(null), decoder.encoding equals utf8
this._readableState.encoding = this._readableState.decoder.encoding;
return this;
};
Expand Down
15 changes: 15 additions & 0 deletions test/parallel/test-stream-readable-setEncoding-null.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
'use strict';

require('../common');
const assert = require('assert');
const { Readable } = require('stream');


{
const readable = new Readable({ encoding: 'hex' });
assert.strictEqual(readable._readableState.encoding, 'hex');

readable.setEncoding(null);

assert.strictEqual(readable._readableState.encoding, 'utf8');
}

0 comments on commit 72ebad2

Please sign in to comment.