instanceof Buffer to Buffer.isBuffer()
This commit is contained in:
parent
6961bc568f
commit
02729d4af7
@ -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++) {
|
||||
|
12
lib/fs.js
12
lib/fs.js
@ -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];
|
||||
@ -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];
|
||||
@ -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];
|
||||
@ -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];
|
||||
|
||||
@ -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);
|
||||
}
|
||||
});
|
||||
@ -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';
|
||||
|
@ -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");
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user