Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings
This repository was archived by the owner on Apr 22, 2023. It is now read-only.

Commit02729d4

Browse files
committed
instanceof Buffer to Buffer.isBuffer()
1 parent6961bc5 commit02729d4

File tree

3 files changed

+11
-7
lines changed

3 files changed

+11
-7
lines changed

‎lib/buffer.js

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,10 @@ function toHex (n) {
77
returnn.toString(16);
88
}
99

10+
Buffer.isBuffer=function(b){
11+
returnbinstanceofBuffer;
12+
};
13+
1014
Buffer.prototype.inspect=function(){
1115
vars="<Buffer ";
1216
for(vari=0;i<this.length;i++){

‎lib/fs.js

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -150,7 +150,7 @@ fs.openSync = function (path, flags, mode) {
150150
};
151151

152152
fs.read=function(fd,buffer,offset,length,position,callback){
153-
if(!(bufferinstanceofBuffer)){
153+
if(!Buffer.isBuffer(buffer)){
154154
// legacy string interface (fd, length, position, encoding, callback)
155155
varcb=arguments[4],
156156
encoding=arguments[3];
@@ -175,7 +175,7 @@ fs.read = function (fd, buffer, offset, length, position, callback) {
175175

176176
fs.readSync=function(fd,buffer,offset,length,position){
177177
varlegacy=false;
178-
if(!(bufferinstanceofBuffer)){
178+
if(!Buffer.isBuffer(buffer)){
179179
// legacy string interface (fd, length, position, encoding, callback)
180180
legacy=true;
181181
encoding=arguments[3];
@@ -198,7 +198,7 @@ fs.readSync = function (fd, buffer, offset, length, position) {
198198
};
199199

200200
fs.write=function(fd,buffer,offset,length,position,callback){
201-
if(!(bufferinstanceofBuffer)){
201+
if(!Buffer.isBuffer(buffer)){
202202
// legacy string interface (fd, data, position, encoding, callback)
203203
callback=arguments[4];
204204
position=arguments[2];
@@ -212,7 +212,7 @@ fs.write = function (fd, buffer, offset, length, position, callback) {
212212
};
213213

214214
fs.writeSync=function(fd,buffer,offset,length,position){
215-
if(!(bufferinstanceofBuffer)){
215+
if(!Buffer.isBuffer(buffer)){
216216
// legacy string interface (fd, data, position, encoding)
217217
position=arguments[2];
218218

@@ -384,7 +384,7 @@ fs.writeFile = function (path, data, encoding_, callback) {
384384
if(openErr){
385385
if(callback)callback(openErr);
386386
}else{
387-
varbuffer=datainstanceofBuffer ?data :newBuffer(data,encoding);
387+
varbuffer=Buffer.isBuffer(data) ?data :newBuffer(data,encoding);
388388
writeAll(fd,buffer,callback);
389389
}
390390
});
@@ -864,7 +864,7 @@ WriteStream.prototype.write = function (data) {
864864
cb=arguments[arguments.length-1];
865865
}
866866

867-
if(datainstanceofBuffer){
867+
if(Buffer.isBuffer(data)){
868868
this._queue.push([fs.write,data,0,data.length,null,cb]);
869869
}else{
870870
varencoding='utf8';

‎lib/http.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -433,7 +433,7 @@ OutgoingMessage.prototype.write = function (chunk, encoding) {
433433
}
434434

435435
if(typeofchunk!=="string"
436-
&&!(chunkinstanceofBuffer)
436+
&&!Buffer.isBuffer(chunk)
437437
&&!Array.isArray(chunk)){
438438
thrownewTypeError("first argument must be a string, Array, or Buffer");
439439
}

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp