Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 12 additions & 2 deletions lib/byline.js
Original file line number Diff line number Diff line change
Expand Up @@ -140,16 +140,26 @@ LineStream.prototype._flush = function(done) {
this._pushBuffer(this._chunkEncoding, 0, done);
};

LineStream.prototype._toBuffer = function(string, encoding) {
if (typeof Buffer.from === 'function') {
return Buffer.from(string, encoding);
} else {
// this was deprecated in node v5 in favor
// of Buffer.from(string, encoding)
return new Buffer(string, encoding);
}
}

// see Readable::push
LineStream.prototype._reencode = function(line, chunkEncoding) {
if (this.encoding && this.encoding != chunkEncoding) {
return new Buffer(line, chunkEncoding).toString(this.encoding);
return this._toBuffer(line, chunkEncoding).toString(this.encoding);
}
else if (this.encoding) {
// this should be the most common case, i.e. we're using an encoded source stream
return line;
}
else {
return new Buffer(line, chunkEncoding);
return this._toBuffer(line, chunkEncoding);
}
};