Skip to content

Commit

Permalink
lib: use Buffer.isBuffer() consistently
Browse files Browse the repository at this point in the history
  • Loading branch information
TimothyGu committed Sep 21, 2017
1 parent 4fceb19 commit 2eab4f8
Show file tree
Hide file tree
Showing 5 changed files with 10 additions and 10 deletions.
4 changes: 2 additions & 2 deletions lib/_http_outgoing.js
Original file line number Diff line number Diff line change
Expand Up @@ -645,7 +645,7 @@ function write_(msg, chunk, encoding, callback, fromEnd) {
return true;
}

if (!fromEnd && typeof chunk !== 'string' && !(chunk instanceof Buffer)) {
if (!fromEnd && typeof chunk !== 'string' && !Buffer.isBuffer(chunk)) {
throw new errors.TypeError('ERR_INVALID_ARG_TYPE', 'first argument',
['string', 'buffer']);
}
Expand Down Expand Up @@ -743,7 +743,7 @@ OutgoingMessage.prototype.end = function end(chunk, encoding, callback) {

var uncork;
if (chunk) {
if (typeof chunk !== 'string' && !(chunk instanceof Buffer)) {
if (typeof chunk !== 'string' && !Buffer.isBuffer(chunk)) {
throw new errors.TypeError('ERR_INVALID_ARG_TYPE', 'first argument',
['string', 'buffer']);
}
Expand Down
4 changes: 2 additions & 2 deletions lib/buffer.js
Original file line number Diff line number Diff line change
Expand Up @@ -567,15 +567,15 @@ Buffer.byteLength = byteLength;
Object.defineProperty(Buffer.prototype, 'parent', {
enumerable: true,
get() {
if (!(this instanceof Buffer))
if (!Buffer.isBuffer(this))
return undefined;
return this.buffer;
}
});
Object.defineProperty(Buffer.prototype, 'offset', {
enumerable: true,
get() {
if (!(this instanceof Buffer))
if (!Buffer.isBuffer(this))
return undefined;
return this.byteOffset;
}
Expand Down
2 changes: 1 addition & 1 deletion lib/fs.js
Original file line number Diff line number Diff line change
Expand Up @@ -2198,7 +2198,7 @@ WriteStream.prototype.open = function() {


WriteStream.prototype._write = function(data, encoding, cb) {
if (!(data instanceof Buffer))
if (!Buffer.isBuffer(data))
return this.emit('error', new Error('Invalid data'));

if (typeof this.fd !== 'number') {
Expand Down
8 changes: 4 additions & 4 deletions lib/net.js
Original file line number Diff line number Diff line change
Expand Up @@ -694,7 +694,7 @@ protoGetter('localPort', function localPort() {


Socket.prototype.write = function(chunk, encoding, cb) {
if (typeof chunk !== 'string' && !(chunk instanceof Buffer)) {
if (typeof chunk !== 'string' && !Buffer.isBuffer(chunk)) {
throw new TypeError(
'Invalid data, chunk must be a string or buffer, not ' + typeof chunk);
}
Expand Down Expand Up @@ -752,7 +752,7 @@ Socket.prototype._writeGeneric = function(writev, data, encoding, cb) {
if (err === 0) req._chunks = chunks;
} else {
var enc;
if (data instanceof Buffer) {
if (Buffer.isBuffer(data)) {
enc = 'buffer';
} else {
enc = encoding;
Expand Down Expand Up @@ -821,7 +821,7 @@ protoGetter('bytesWritten', function bytesWritten() {
return undefined;

state.getBuffer().forEach(function(el) {
if (el.chunk instanceof Buffer)
if (Buffer.isBuffer(el.chunk))
bytes += el.chunk.length;
else
bytes += Buffer.byteLength(el.chunk, el.encoding);
Expand All @@ -832,7 +832,7 @@ protoGetter('bytesWritten', function bytesWritten() {
for (var i = 0; i < data.length; i++) {
const chunk = data[i];

if (data.allBuffers || chunk instanceof Buffer)
if (data.allBuffers || Buffer.isBuffer(chunk))
bytes += chunk.length;
else
bytes += Buffer.byteLength(chunk.chunk, chunk.encoding);
Expand Down
2 changes: 1 addition & 1 deletion lib/readline.js
Original file line number Diff line number Diff line change
Expand Up @@ -973,7 +973,7 @@ Interface.prototype._ttyWrite = function(s, key) {
// falls through

default:
if (s instanceof Buffer)
if (Buffer.isBuffer(s))
s = s.toString('utf-8');

if (s) {
Expand Down

0 comments on commit 2eab4f8

Please sign in to comment.