Skip to content
This repository has been archived by the owner on Apr 22, 2023. It is now read-only.

Commit

Permalink
instanceof Buffer to Buffer.isBuffer()
Browse files Browse the repository at this point in the history
  • Loading branch information
ry committed Jul 15, 2010
1 parent 6961bc5 commit 02729d4
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 7 deletions.
4 changes: 4 additions & 0 deletions lib/buffer.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,10 @@ function toHex (n) {
return n.toString(16);
}

Buffer.isBuffer = function (b) {
return b instanceof Buffer;
};

Buffer.prototype.inspect = function () {
var s = "<Buffer ";
for (var i = 0; i < this.length; i++) {
Expand Down
12 changes: 6 additions & 6 deletions lib/fs.js
Original file line number Diff line number Diff line change
Expand Up @@ -150,7 +150,7 @@ fs.openSync = function (path, flags, mode) {
};

fs.read = function (fd, buffer, offset, length, position, callback) {
if (!(buffer instanceof Buffer)) {
if (!Buffer.isBuffer(buffer)) {
// legacy string interface (fd, length, position, encoding, callback)
var cb = arguments[4],
encoding = arguments[3];
Expand All @@ -175,7 +175,7 @@ fs.read = function (fd, buffer, offset, length, position, callback) {

fs.readSync = function (fd, buffer, offset, length, position) {
var legacy = false;
if (!(buffer instanceof Buffer)) {
if (!Buffer.isBuffer(buffer)) {
// legacy string interface (fd, length, position, encoding, callback)
legacy = true;
encoding = arguments[3];
Expand All @@ -198,7 +198,7 @@ fs.readSync = function (fd, buffer, offset, length, position) {
};

fs.write = function (fd, buffer, offset, length, position, callback) {
if (!(buffer instanceof Buffer)) {
if (!Buffer.isBuffer(buffer)) {
// legacy string interface (fd, data, position, encoding, callback)
callback = arguments[4];
position = arguments[2];
Expand All @@ -212,7 +212,7 @@ fs.write = function (fd, buffer, offset, length, position, callback) {
};

fs.writeSync = function (fd, buffer, offset, length, position) {
if (!(buffer instanceof Buffer)) {
if (!Buffer.isBuffer(buffer)) {
// legacy string interface (fd, data, position, encoding)
position = arguments[2];

Expand Down Expand Up @@ -384,7 +384,7 @@ fs.writeFile = function (path, data, encoding_, callback) {
if (openErr) {
if (callback) callback(openErr);
} else {
var buffer = data instanceof Buffer ? data : new Buffer(data, encoding);
var buffer = Buffer.isBuffer(data) ? data : new Buffer(data, encoding);
writeAll(fd, buffer, callback);
}
});
Expand Down Expand Up @@ -864,7 +864,7 @@ WriteStream.prototype.write = function (data) {
cb = arguments[arguments.length-1];
}

if (data instanceof Buffer) {
if (Buffer.isBuffer(data)) {
this._queue.push([fs.write, data, 0, data.length, null, cb]);
} else {
var encoding = 'utf8';
Expand Down
2 changes: 1 addition & 1 deletion lib/http.js
Original file line number Diff line number Diff line change
Expand Up @@ -433,7 +433,7 @@ OutgoingMessage.prototype.write = function (chunk, encoding) {
}

if (typeof chunk !== "string"
&& !(chunk instanceof Buffer)
&& !Buffer.isBuffer(chunk)
&& !Array.isArray(chunk)) {
throw new TypeError("first argument must be a string, Array, or Buffer");
}
Expand Down

0 comments on commit 02729d4

Please sign in to comment.