@ -415,30 +415,30 @@ Buffer.byteLength = SlowBuffer.byteLength;
// fill(value, start=0, end=buffer.length)
Buffer . prototype . fill = function fill ( value , start , end ) {
Buffer . prototype . fill = function fill ( value , start , end ) {
value || ( value = 0 ) ;
start || ( start = 0 ) ;
end || ( end = this . length ) ;
end || ( end = this . length ) ;
if ( typeof value === "string" ) {
if ( typeof value === 'string' ) {
value = value . charCodeAt ( 0 ) ;
}
if ( ! ( typeof value === "number" ) || isNaN ( value ) ) {
throw new Error ( "value is not a number" ) ;
if ( ! ( typeof value === 'number' ) || isNaN ( value ) ) {
throw new Error ( 'value is not a number' ) ;
}
if ( end < start ) throw new Error ( "end < start" ) ;
if ( end < start ) throw new Error ( 'end < start' ) ;
// Fill 0 bytes; we're done
if ( end === start ) return 0 ;
if ( this . length == 0 ) return 0 ;
if ( start < 0 || start >= this . length ) {
throw new Error ( "start out of bounds" ) ;
throw new Error ( 'start out of bounds' ) ;
}
if ( end < 0 || end > this . length ) {
throw new Error ( "end out of bounds" ) ;
throw new Error ( 'end out of bounds' ) ;
}
return this . parent . fill ( value ,
@ -524,42 +524,28 @@ Buffer.prototype.asciiWrite = function(string, offset) {
return this . write ( string , offset , 'ascii' ) ;
} ;
Buffer . prototype . readUInt8 = function ( offset , e ndian) {
Buffer . prototype . readUInt8NoChk = function ( offset , bigE ndian) {
var buffer = this ;
return buffer [ offset ] ;
} ;
assert . ok ( endian !== undefined && endian !== null ,
'missing endian' ) ;
assert . ok ( endian == 'big' || endian == 'little' ,
'bad endian value' ) ;
Buffer . prototype . readUInt8 = function ( offset , bigEndian ) {
var buffer = this ;
assert . ok ( offset !== undefined && offset !== null ,
'missing offset' ) ;
'missing offset' ) ;
assert . ok ( offset < buffer . length ,
'Trying to read beyond buffer length' ) ;
'Trying to read beyond buffer length' ) ;
return buffer [ offset ] ;
return buffer . readUInt8NoChk ( offset , bigEndian ) ;
} ;
Buffer . prototype . readUInt16 = function ( offset , endian ) {
Buffer . prototype . readUInt16NoChk = function ( offset , bigEndian ) {
var val = 0 ;
var buffer = this ;
assert . ok ( endian !== undefined && endian !== null ,
'missing endian' ) ;
assert . ok ( endian == 'big' || endian == 'little' ,
'bad endian value' ) ;
assert . ok ( offset !== undefined && offset !== null ,
'missing offset' ) ;
assert . ok ( offset + 1 < buffer . length ,
'Trying to read beyond buffer length' ) ;
if ( endian == 'big' ) {
if ( bigEndian ) {
val = buffer [ offset ] << 8 ;
val |= buffer [ offset + 1 ] ;
} else {
@ -570,24 +556,26 @@ Buffer.prototype.readUInt16 = function(offset, endian) {
return val ;
} ;
Buffer . prototype . readUInt32 = function ( offset , endian ) {
var val = 0 ;
Buffer . prototype . readUInt16 = function ( offset , bigEndian ) {
var buffer = this ;
assert . ok ( endian !== undefined && endian !== null ,
'missing endian' ) ;
assert . ok ( endian == 'big' || endian == 'little' ,
'bad endian value' ) ;
assert . ok ( typeof ( bigEndian ) === 'boolean' ,
'missing or invalid endian' ) ;
assert . ok ( offset !== undefined && offset !== null ,
'missing offset' ) ;
'missing offset' ) ;
assert . ok ( offset + 3 < buffer . length ,
'Trying to read beyond buffer length' ) ;
assert . ok ( offset + 1 < buffer . length ,
'Trying to read beyond buffer length' ) ;
return buffer . readUInt16NoChk ( offset , bigEndian ) ;
} ;
Buffer . prototype . readUInt32NoChk = function ( offset , bigEndian ) {
var val = 0 ;
var buffer = this ;
if ( endian == 'big' ) {
if ( bigEndian ) {
val = buffer [ offset + 1 ] << 16 ;
val |= buffer [ offset + 2 ] << 8 ;
val |= buffer [ offset + 3 ] ;
@ -602,6 +590,22 @@ Buffer.prototype.readUInt32 = function(offset, endian) {
return val ;
} ;
Buffer . prototype . readUInt32 = function ( offset , bigEndian ) {
var val = 0 ;
var buffer = this ;
assert . ok ( typeof ( bigEndian ) === 'boolean' ,
'missing or invalid endian' ) ;
assert . ok ( offset !== undefined && offset !== null ,
'missing offset' ) ;
assert . ok ( offset + 3 < buffer . length ,
'Trying to read beyond buffer length' ) ;
return buffer . readUInt32NoChk ( offset , bigEndian ) ;
} ;
/ *
* Signed integer types , yay team ! A reminder on how two ' s complement actually
@ -648,21 +652,15 @@ Buffer.prototype.readUInt32 = function(offset, endian) {
* ( 0x007f + 1 ) * - 1
* ( 0x0080 ) * - 1
* /
Buffer . prototype . readInt8 = function ( offset , e ndian) {
Buffer . prototype . readInt8 = function ( offset , bigE ndian) {
var buffer = this ;
var neg ;
assert . ok ( endian !== undefined && endian !== null ,
'missing endian' ) ;
assert . ok ( endian == 'big' || endian == 'little' ,
'bad endian value' ) ;
assert . ok ( offset !== undefined && offset !== null ,
'missing offset' ) ;
'missing offset' ) ;
assert . ok ( offset < buffer . length ,
'Trying to read beyond buffer length' ) ;
'Trying to read beyond buffer length' ) ;
neg = buffer [ offset ] & 0x80 ;
if ( ! neg ) {
@ -673,23 +671,20 @@ Buffer.prototype.readInt8 = function(offset, endian) {
} ;
Buffer . prototype . readInt16 = function ( offset , e ndian) {
Buffer . prototype . readInt16 = function ( offset , bigE ndian) {
var buffer = this ;
var neg ;
assert . ok ( endian !== undefined && endian !== null ,
'missing endian' ) ;
assert . ok ( endian == 'big' || endian == 'little' ,
'bad endian value' ) ;
assert . ok ( typeof ( bigEndian ) === 'boolean' ,
'missing or invalid endian' ) ;
assert . ok ( offset !== undefined && offset !== null ,
'missing offset' ) ;
'missing offset' ) ;
assert . ok ( offset + 1 < buffer . length ,
'Trying to read beyond buffer length' ) ;
'Trying to read beyond buffer length' ) ;
val = buffer . readUInt16 ( offset , e ndian) ;
val = buffer . readUInt16NoChk ( offset , bigE ndian) ;
neg = val & 0x8000 ;
if ( ! neg ) {
return val ;
@ -699,23 +694,20 @@ Buffer.prototype.readInt16 = function(offset, endian) {
} ;
Buffer . prototype . readInt32 = function ( offset , e ndian) {
Buffer . prototype . readInt32 = function ( offset , bigE ndian) {
var buffer = this ;
var neg ;
assert . ok ( endian !== undefined && endian !== null ,
'missing endian' ) ;
assert . ok ( endian == 'big' || endian == 'little' ,
'bad endian value' ) ;
assert . ok ( typeof ( bigEndian ) === 'boolean' ,
'missing or invalid endian' ) ;
assert . ok ( offset !== undefined && offset !== null ,
'missing offset' ) ;
'missing offset' ) ;
assert . ok ( offset + 3 < buffer . length ,
'Trying to read beyond buffer length' ) ;
'Trying to read beyond buffer length' ) ;
val = buffer . readUInt32 ( offset , e ndian) ;
val = buffer . readUInt32NoChk ( offset , bigE ndian) ;
neg = val & 0x80000000 ;
if ( ! neg ) {
return ( val ) ;
@ -725,40 +717,30 @@ Buffer.prototype.readInt32 = function(offset, endian) {
} ;
Buffer . prototype . readFloat = function ( offset , e ndian) {
Buffer . prototype . readFloat = function ( offset , bigE ndian) {
var buffer = this ;
assert . ok ( endian !== undefined && endian !== null ,
'missing endian' ) ;
assert . ok ( endian == 'big' || endian == 'little' ,
'bad endian value' ) ;
assert . ok ( offset !== undefined && offset !== null ,
'missing offset' ) ;
assert . ok ( typeof ( bigEndian ) === 'boolean' ,
'missing or invalid endian' ) ;
assert . ok ( offset + 3 < buffer . length ,
'Trying to read beyond buffer length' ) ;
'Trying to read beyond buffer length' ) ;
return require ( 'buffer_ieee754' ) . readIEEE754 ( buffer , offset , endian , 23 , 4 ) ;
return require ( 'buffer_ieee754' ) . readIEEE754 ( buffer , offset , bigEndian ,
23 , 4 ) ;
} ;
Buffer . prototype . readDouble = function ( offset , e ndian) {
Buffer . prototype . readDouble = function ( offset , bigE ndian) {
var buffer = this ;
assert . ok ( endian !== undefined && endian !== null ,
'missing endian' ) ;
assert . ok ( endian == 'big' || endian == 'little' ,
'bad endian value' ) ;
assert . ok ( offset !== undefined && offset !== null ,
'missing offset' ) ;
assert . ok ( typeof ( bigEndian ) === 'boolean' ,
'missing or invalid endian' ) ;
assert . ok ( offset + 7 < buffer . length ,
'Trying to read beyond buffer length' ) ;
'Trying to read beyond buffer length' ) ;
return require ( 'buffer_ieee754' ) . readIEEE754 ( buffer , offset , endian , 52 , 8 ) ;
return require ( 'buffer_ieee754' ) . readIEEE754 ( buffer , offset , bigEndian ,
52 , 8 ) ;
} ;
@ -773,90 +755,78 @@ Buffer.prototype.readDouble = function(offset, endian) {
* /
function verifuint ( value , max ) {
assert . ok ( typeof ( value ) == 'number' ,
'cannot write a non-number as a number' ) ;
'cannot write a non-number as a number' ) ;
assert . ok ( value >= 0 ,
'specified a negative value for writing an unsigned value' ) ;
'specified a negative value for writing an unsigned value' ) ;
assert . ok ( value <= max , 'value is larger than maximum value for type' ) ;
assert . ok ( Math . floor ( value ) === value , 'value has a fractional component' ) ;
}
Buffer . prototype . writeUInt8NoChk = function ( value , offset , bigEndian ) {
var buffer = this ;
buffer [ offset ] = value ;
} ;
Buffer . prototype . writeUInt8 = function ( value , offset , endian ) {
Buffer . prototype . writeUInt8 = function ( value , offset , bigE ndian) {
var buffer = this ;
assert . ok ( value !== undefined && value !== null ,
'missing value' ) ;
assert . ok ( endian !== undefined && endian !== null ,
'missing endian' ) ;
'missing value' ) ;
assert . ok ( endian == 'big' || endian == 'little ',
'bad endian value ') ;
assert . ok ( typeof ( bigEndian ) === 'boolean' ,
'missing or invalid endian' ) ;
assert . ok ( offset !== undefined && offset !== null ,
'missing offset' ) ;
'missing offset' ) ;
assert . ok ( offset < buffer . length ,
'trying to write beyond buffer length' ) ;
'trying to write beyond buffer length' ) ;
verifuint ( value , 0xff ) ;
buffer [ offset ] = value ;
} ;
buffer . writeUInt8NoChk ( value , offset , bigEndian ) ;
} ;
Buffer . prototype . writeUInt16 = function ( value , offset , endian ) {
Buffer . prototype . writeUInt16NoChk = function ( value , offset , bigE ndian) {
var buffer = this ;
assert . ok ( value !== undefined && value !== null ,
'missing value' ) ;
assert . ok ( endian !== undefined && endian !== null ,
'missing endian' ) ;
assert . ok ( endian == 'big' || endian == 'little' ,
'bad endian value' ) ;
assert . ok ( offset !== undefined && offset !== null ,
'missing offset' ) ;
assert . ok ( offset + 1 < buffer . length ,
'trying to write beyond buffer length' ) ;
verifuint ( value , 0xffff ) ;
if ( endian == 'big' ) {
if ( bigEndian ) {
buffer [ offset ] = ( value & 0xff00 ) >>> 8 ;
buffer [ offset + 1 ] = value & 0x00ff ;
} else {
buffer [ offset + 1 ] = ( value & 0xff00 ) >>> 8 ;
buffer [ offset ] = value & 0x00ff ;
}
} ;
} ;
Buffer . prototype . writeUInt32 = function ( value , offset , e ndian) {
Buffer . prototype . writeUInt16 = function ( value , offset , bigEndian ) {
var buffer = this ;
assert . ok ( value !== undefined && value !== null ,
'missing value' ) ;
assert . ok ( endian !== undefined && endian !== null ,
'missing endian' ) ;
'missing value' ) ;
assert . ok ( endian == 'big' || endian == 'little ',
'bad endian value ') ;
assert . ok ( typeof ( bigEndian ) === 'boolean' ,
'missing or invalid endian' ) ;
assert . ok ( offset !== undefined && offset !== null ,
'missing offset' ) ;
'missing offset' ) ;
assert . ok ( offset + 3 < buffer . length ,
'trying to write beyond buffer length' ) ;
assert . ok ( offset + 1 < buffer . length ,
'trying to write beyond buffer length' ) ;
verifuint ( value , 0xffffffff ) ;
if ( endian == 'big' ) {
verifuint ( value , 0xffff ) ;
buffer . writeUInt16NoChk ( value , offset , bigEndian ) ;
} ;
Buffer . prototype . writeUInt32NoChk = function ( value , offset , bigEndian ) {
var buffer = this ;
if ( bigEndian ) {
buffer [ offset ] = ( value >>> 24 ) & 0xff ;
buffer [ offset + 1 ] = ( value >>> 16 ) & 0xff ;
buffer [ offset + 2 ] = ( value >>> 8 ) & 0xff ;
@ -869,6 +839,26 @@ Buffer.prototype.writeUInt32 = function(value, offset, endian) {
}
} ;
Buffer . prototype . writeUInt32 = function ( value , offset , bigEndian ) {
var buffer = this ;
assert . ok ( value !== undefined && value !== null ,
'missing value' ) ;
assert . ok ( typeof ( bigEndian ) === 'boolean' ,
'missing or invalid endian' ) ;
assert . ok ( offset !== undefined && offset !== null ,
'missing offset' ) ;
assert . ok ( offset + 3 < buffer . length ,
'trying to write beyond buffer length' ) ;
verifuint ( value , 0xffffffff ) ;
buffer . writeUInt32NoChk ( value , offset , bigEndian ) ;
} ;
/ *
* We now move onto our friends in the signed number category . Unlike unsigned
@ -912,7 +902,7 @@ Buffer.prototype.writeUInt32 = function(value, offset, endian) {
* /
function verifsint ( value , max , min ) {
assert . ok ( typeof ( value ) == 'number' ,
'cannot write a non-number as a number' ) ;
'cannot write a non-number as a number' ) ;
assert . ok ( value <= max , 'value larger than maximum allowed value' ) ;
@ -924,7 +914,7 @@ function verifsint(value, max, min) {
function verifIEEE754 ( value , max , min ) {
assert . ok ( typeof ( value ) == 'number' ,
'cannot write a non-number as a number' ) ;
'cannot write a non-number as a number' ) ;
assert . ok ( value <= max , 'value larger than maximum allowed value' ) ;
@ -932,131 +922,118 @@ function verifIEEE754(value, max, min) {
}
Buffer . prototype . writeInt8 = function ( value , offset , e ndian) {
Buffer . prototype . writeInt8 = function ( value , offset , bigE ndian) {
var buffer = this ;
assert . ok ( value !== undefined && value !== null ,
'missing value' ) ;
'missing value' ) ;
assert . ok ( endian !== undefined && endian !== null ,
'missing endian' ) ;
assert . ok ( endian == 'big' || endian == 'little' ,
'bad endian value' ) ;
assert . ok ( typeof ( bigEndian ) === 'boolean' ,
'missing or invalid endian' ) ;
assert . ok ( offset !== undefined && offset !== null ,
'missing offset' ) ;
'missing offset' ) ;
assert . ok ( offset < buffer . length ,
'Trying to write beyond buffer length' ) ;
'Trying to write beyond buffer length' ) ;
verifsint ( value , 0x7f , - 0xf0 ) ;
if ( value >= 0 ) {
buffer . writeUInt8 ( value , offset , e ndian) ;
buffer . writeUInt8NoChk ( value , offset , bigE ndian) ;
} else {
buffer . writeUInt8 ( 0xff + value + 1 , offset , e ndian) ;
buffer . writeUInt8NoChk ( 0xff + value + 1 , offset , bigE ndian) ;
}
} ;
Buffer . prototype . writeInt16 = function ( value , offset , e ndian) {
Buffer . prototype . writeInt16 = function ( value , offset , bigE ndian) {
var buffer = this ;
assert . ok ( value !== undefined && value !== null ,
'missing value' ) ;
assert . ok ( endian !== undefined && endian !== null ,
'missing endian' ) ;
'missing value' ) ;
assert . ok ( endian == 'big' || endian == 'little ',
'bad endian value ') ;
assert . ok ( typeof ( bigEndian ) === 'boolean' ,
'missing or invalid endian' ) ;
assert . ok ( offset !== undefined && offset !== null ,
'missing offset' ) ;
'missing offset' ) ;
assert . ok ( offset + 1 < buffer . length ,
'Trying to write beyond buffer length' ) ;
'Trying to write beyond buffer length' ) ;
verifsint ( value , 0x7fff , - 0xf000 ) ;
if ( value >= 0 ) {
buffer . writeUInt16 ( value , offset , e ndian) ;
buffer . writeUInt16NoChk ( value , offset , bigE ndian) ;
} else {
buffer . writeUInt16 ( 0xffff + value + 1 , offset , e ndian) ;
buffer . writeUInt16NoChk ( 0xffff + value + 1 , offset , bigE ndian) ;
}
} ;
Buffer . prototype . writeInt32 = function ( value , offset , e ndian) {
Buffer . prototype . writeInt32 = function ( value , offset , bigE ndian) {
var buffer = this ;
assert . ok ( value !== undefined && value !== null ,
'missing value' ) ;
assert . ok ( endian !== undefined && endian !== null ,
'missing endian' ) ;
'missing value' ) ;
assert . ok ( endian == 'big' || endian == 'little ',
'bad endian value ') ;
assert . ok ( typeof ( bigEndian ) === 'boolean' ,
'missing or invalid endian' ) ;
assert . ok ( offset !== undefined && offset !== null ,
'missing offset' ) ;
'missing offset' ) ;
assert . ok ( offset + 3 < buffer . length ,
'Trying to write beyond buffer length' ) ;
'Trying to write beyond buffer length' ) ;
verifsint ( value , 0x7fffffff , - 0xf0000000 ) ;
if ( value >= 0 ) {
buffer . writeUInt32 ( value , offset , e ndian) ;
buffer . writeUInt32NoChk ( value , offset , bigE ndian) ;
} else {
buffer . writeUInt32 ( 0xffffffff + value + 1 , offset , e ndian) ;
buffer . writeUInt32NoChk ( 0xffffffff + value + 1 , offset , bigE ndian) ;
}
} ;
Buffer . prototype . writeFloat = function ( value , offset , e ndian) {
Buffer . prototype . writeFloat = function ( value , offset , bigE ndian) {
var buffer = this ;
assert . ok ( value !== undefined && value !== null ,
'missing value' ) ;
'missing value' ) ;
assert . ok ( endian !== undefined && endian !== null ,
'missing endian' ) ;
assert . ok ( endian == 'big' || endian == 'little' ,
'bad endian value' ) ;
assert . ok ( typeof ( bigEndian ) === 'boolean' ,
'missing or invalid endian' ) ;
assert . ok ( offset !== undefined && offset !== null ,
'missing offset' ) ;
'missing offset' ) ;
assert . ok ( offset + 3 < buffer . length ,
'Trying to write beyond buffer length' ) ;
'Trying to write beyond buffer length' ) ;
verifIEEE754 ( value , 3.4028234663852886 e + 38 , - 3.4028234663852886 e + 38 ) ;
require ( 'buffer_ieee754' ) . writeIEEE754 ( buffer , value , offset , endian , 23 , 4 ) ;
require ( 'buffer_ieee754' ) . writeIEEE754 ( buffer , value , offset , bigEndian ,
23 , 4 ) ;
} ;
Buffer . prototype . writeDouble = function ( value , offset , e ndian) {
Buffer . prototype . writeDouble = function ( value , offset , bigE ndian) {
var buffer = this ;
assert . ok ( value !== undefined && value !== null ,
'missing value' ) ;
assert . ok ( endian !== undefined && endian !== null ,
'missing endian' ) ;
'missing value' ) ;
assert . ok ( endian == 'big' || endian == 'little ',
'bad endian value ') ;
assert . ok ( typeof ( bigEndian ) === 'boolean' ,
'missing or invalid endian' ) ;
assert . ok ( offset !== undefined && offset !== null ,
'missing offset' ) ;
'missing offset' ) ;
assert . ok ( offset + 7 < buffer . length ,
'Trying to write beyond buffer length' ) ;
'Trying to write beyond buffer length' ) ;
verifIEEE754 ( value , 1.7976931348623157 E + 308 , - 1.7976931348623157 E + 308 ) ;
require ( 'buffer_ieee754' ) . writeIEEE754 ( buffer , value , offset , endian , 52 , 8 ) ;
require ( 'buffer_ieee754' ) . writeIEEE754 ( buffer , value , offset , bigEndian ,
52 , 8 ) ;
} ;