@ -143,8 +143,9 @@ function Buffer(arg, encodingOrOffset, length) {
// Common case.
if ( typeof arg === 'number' ) {
if ( typeof encodingOrOffset === 'string' ) {
throw new errors . TypeError ( 'ERR_INVALID_ARG_TYPE' , 'string' ,
'string' , arg ) ;
throw new errors . TypeError (
'ERR_INVALID_ARG_TYPE' , 'string' , 'string' , arg
) ;
}
return Buffer . alloc ( arg ) ;
}
@ -172,13 +173,19 @@ Buffer.from = function(value, encodingOrOffset, length) {
if ( isAnyArrayBuffer ( value ) )
return fromArrayBuffer ( value , encodingOrOffset , length ) ;
if ( value == null )
throw new errors . TypeError ( 'ERR_INVALID_ARG_TYPE' , 'first argument' ,
[ 'string' , 'buffer' , 'arrayBuffer' , 'array' , 'array-like object' ] , value ) ;
if ( value == null ) {
throw new errors . TypeError (
'ERR_INVALID_ARG_TYPE' ,
'first argument' ,
[ 'string' , 'buffer' , 'arrayBuffer' , 'array' , 'array-like object' ] ,
value
) ;
}
if ( typeof value === 'number' )
throw new errors . TypeError ( 'ERR_INVALID_ARG_TYPE' , 'value' , 'not number' ,
value ) ;
throw new errors . TypeError (
'ERR_INVALID_ARG_TYPE' , 'value' , 'not number' , value
) ;
const valueOf = value . valueOf && value . valueOf ( ) ;
if ( valueOf != null && valueOf !== value )
@ -194,8 +201,11 @@ Buffer.from = function(value, encodingOrOffset, length) {
length ) ;
}
throw new errors . TypeError ( 'ERR_INVALID_ARG_TYPE' , 'first argument' ,
[ 'string' , 'buffer' , 'arrayBuffer' , 'array' , 'array-like object' ] ) ;
throw new errors . TypeError (
'ERR_INVALID_ARG_TYPE' ,
'first argument' ,
[ 'string' , 'buffer' , 'arrayBuffer' , 'array' , 'array-like object' ]
) ;
} ;
Object . setPrototypeOf ( Buffer , Uint8Array ) ;
@ -397,8 +407,9 @@ Buffer.isBuffer = function isBuffer(b) {
Buffer . compare = function compare ( a , b ) {
if ( ! isUint8Array ( a ) || ! isUint8Array ( b ) ) {
throw new errors . TypeError ( 'ERR_INVALID_ARG_TYPE' , [ 'buf1' , 'buf2' ] ,
[ 'buffer' , 'uint8Array' ] ) ;
throw new errors . TypeError (
'ERR_INVALID_ARG_TYPE' , [ 'buf1' , 'buf2' ] , [ 'buffer' , 'uint8Array' ]
) ;
}
if ( a === b ) {
@ -415,8 +426,9 @@ Buffer.isEncoding = function(encoding) {
} ;
Buffer [ internalUtil . kIsEncodingSymbol ] = Buffer . isEncoding ;
const kConcatErr = new errors . TypeError ( 'ERR_INVALID_ARG_TYPE' , 'list' ,
[ 'array' , 'buffer' , 'uint8Array' ] ) ;
const kConcatErr = new errors . TypeError (
'ERR_INVALID_ARG_TYPE' , 'list' , [ 'array' , 'buffer' , 'uint8Array' ]
) ;
Buffer . concat = function ( list , length ) {
var i ;
@ -474,8 +486,9 @@ function byteLength(string, encoding) {
return string . byteLength ;
}
throw new errors . TypeError ( 'ERR_INVALID_ARG_TYPE' , 'string' ,
[ 'string' , 'buffer' , 'arrayBuffer' ] ) ;
throw new errors . TypeError (
'ERR_INVALID_ARG_TYPE' , 'string' , [ 'string' , 'buffer' , 'arrayBuffer' ]
) ;
}
const len = string . length ;
@ -632,9 +645,11 @@ Buffer.prototype.toString = function(encoding, start, end) {
Buffer . prototype . equals = function equals ( b ) {
if ( ! isUint8Array ( b ) )
throw new errors . TypeError ( 'ERR_INVALID_ARG_TYPE' , 'otherBuffer' ,
[ 'buffer' , 'uint8Array' ] ) ;
if ( ! isUint8Array ( b ) ) {
throw new errors . TypeError (
'ERR_INVALID_ARG_TYPE' , 'otherBuffer' , [ 'buffer' , 'uint8Array' ]
) ;
}
if ( this === b )
return true ;
@ -658,9 +673,11 @@ Buffer.prototype.compare = function compare(target,
end ,
thisStart ,
thisEnd ) {
if ( ! isUint8Array ( target ) )
throw new errors . TypeError ( 'ERR_INVALID_ARG_TYPE' , 'target' ,
[ 'buffer' , 'uint8Array' ] ) ;
if ( ! isUint8Array ( target ) ) {
throw new errors . TypeError (
'ERR_INVALID_ARG_TYPE' , 'target' , [ 'buffer' , 'uint8Array' ]
) ;
}
if ( arguments . length === 1 )
return compare_ ( this , target ) ;
@ -739,8 +756,9 @@ function bidirectionalIndexOf(buffer, val, byteOffset, encoding, dir) {
return binding . indexOfNumber ( buffer , val , byteOffset , dir ) ;
}
throw new errors . TypeError ( 'ERR_INVALID_ARG_TYPE' , 'val' ,
[ 'string' , 'buffer' , 'uint8Array' ] ) ;
throw new errors . TypeError (
'ERR_INVALID_ARG_TYPE' , 'val' , [ 'string' , 'buffer' , 'uint8Array' ]
) ;
}
@ -878,8 +896,10 @@ Buffer.prototype.write = function(string, offset, length, encoding) {
// if someone is still calling the obsolete form of write(), tell them.
// we don't want eg buf.write("foo", "utf8", 10) to silently turn into
// buf.write("foo", "utf8"), so we can't ignore extra args
throw new errors . Error ( 'ERR_NO_LONGER_SUPPORTED' ,
'Buffer.write(string, encoding, offset[, length])' ) ;
throw new errors . Error (
'ERR_NO_LONGER_SUPPORTED' ,
'Buffer.write(string, encoding, offset[, length])'
) ;
}
if ( ! encoding ) return this . utf8Write ( string , offset , length ) ;