new Buffer()
A buffer is a sequence of zero or more bytes that can read from or written to and which expands automatically as necessary to accommodate any bytes written to it. You can perhaps think of a buffer as smart byte array.
Please consult the documentation for more information on buffers.
Methods
-
appendBuffer(buff, offset, len) → {Buffer}
-
Appends the specified
Bufferstarting at theoffsetusinglento the end of this Buffer. The buffer will expand as necessary to accommodate any bytes written.Returns a reference to
thisso multiple operations can be appended together.Parameters:
Name Type Description buffBuffer offsetnumber lennumber Returns:
- Type
- Buffer
-
appendByte(b) → {Buffer}
-
Appends the specified
byteto the end of the Buffer. The buffer will expand as necessary to accommodate any bytes written.Returns a reference to
thisso multiple operations can be appended together.Parameters:
Name Type Description bnumber Returns:
- Type
- Buffer
-
appendDouble(d) → {Buffer}
-
Appends the specified
doubleto the end of the Buffer. The buffer will expand as necessary to accommodate any bytes written.Returns a reference to
thisso multiple operations can be appended together.Parameters:
Name Type Description dnumber Returns:
- Type
- Buffer
-
appendFloat(f) → {Buffer}
-
Appends the specified
floatto the end of the Buffer. The buffer will expand as necessary to accommodate any bytes written.Returns a reference to
thisso multiple operations can be appended together.Parameters:
Name Type Description fnumber Returns:
- Type
- Buffer
-
appendInt(i) → {Buffer}
-
Appends the specified
intto the end of the Buffer. The buffer will expand as necessary to accommodate any bytes written.Returns a reference to
thisso multiple operations can be appended together.Parameters:
Name Type Description inumber Returns:
- Type
- Buffer
-
appendLong(l) → {Buffer}
-
Appends the specified
longto the end of the Buffer. The buffer will expand as necessary to accommodate any bytes written.Returns a reference to
thisso multiple operations can be appended together.Parameters:
Name Type Description lnumber Returns:
- Type
- Buffer
-
appendShort(s) → {Buffer}
-
Appends the specified
shortto the end of the Buffer.The buffer will expand as necessary to accommodate any bytes written.Returns a reference to
thisso multiple operations can be appended together.Parameters:
Name Type Description snumber Returns:
- Type
- Buffer
-
appendString(str, enc) → {Buffer}
-
Appends the specified
Stringto the end of the Buffer with the encoding as specified byenc.The buffer will expand as necessary to accommodate any bytes written.
Returns a reference to
thisso multiple operations can be appended together.Parameters:
Name Type Description strstring encstring Returns:
- Type
- Buffer
-
appendUnsignedByte(b) → {Buffer}
-
Appends the specified unsigned
byteto the end of the Buffer. The buffer will expand as necessary to accommodate any bytes written.Returns a reference to
thisso multiple operations can be appended together.Parameters:
Name Type Description bnumber Returns:
- Type
- Buffer
-
appendUnsignedInt(i) → {Buffer}
-
Appends the specified unsigned
intto the end of the Buffer. The buffer will expand as necessary to accommodate any bytes written.Returns a reference to
thisso multiple operations can be appended together.Parameters:
Name Type Description inumber Returns:
- Type
- Buffer
-
appendUnsignedShort(s) → {Buffer}
-
Appends the specified unsigned
shortto the end of the Buffer.The buffer will expand as necessary to accommodate any bytes written.Returns a reference to
thisso multiple operations can be appended together.Parameters:
Name Type Description snumber Returns:
- Type
- Buffer
-
copy() → {Buffer}
-
Returns a copy of the entire Buffer.
Returns:
- Type
- Buffer
-
getBuffer(start, end) → {Buffer}
-
Returns a copy of a sub-sequence the Buffer as a Buffer starting at position
startand ending at positionend - 1Parameters:
Name Type Description startnumber endnumber Returns:
- Type
- Buffer
-
getByte(pos) → {number}
-
Returns the
byteat positionposin the Buffer.Parameters:
Name Type Description posnumber Returns:
- Type
- number
-
getDouble(pos) → {number}
-
Returns the
doubleat positionposin the Buffer.Parameters:
Name Type Description posnumber Returns:
- Type
- number
-
getFloat(pos) → {number}
-
Returns the
floatat positionposin the Buffer.Parameters:
Name Type Description posnumber Returns:
- Type
- number
-
getInt(pos) → {number}
-
Returns the
intat positionposin the Buffer.Parameters:
Name Type Description posnumber Returns:
- Type
- number
-
getLong(pos) → {number}
-
Returns the
longat positionposin the Buffer.Parameters:
Name Type Description posnumber Returns:
- Type
- number
-
getShort(pos) → {number}
-
Returns the
shortat positionposin the Buffer.Parameters:
Name Type Description posnumber Returns:
- Type
- number
-
getString(start, end, enc) → {string}
-
Returns a copy of a sub-sequence the Buffer as a
Stringstarting at positionstartand ending at positionend - 1interpreted as a String in the specified encodingParameters:
Name Type Description startnumber endnumber encstring Returns:
- Type
- string
-
getUnsignedByte(pos) → {number}
-
Returns the unsigned
byteat positionposin the Buffer, as ashort.Parameters:
Name Type Description posnumber Returns:
- Type
- number
-
getUnsignedInt(pos) → {number}
-
Returns the unsigned
intat positionposin the Buffer, as along.Parameters:
Name Type Description posnumber Returns:
- Type
- number
-
getUnsignedShort(pos) → {number}
-
Returns the unsigned
shortat positionposin the Buffer, as anint.Parameters:
Name Type Description posnumber Returns:
- Type
- number
-
length() → {number}
-
Returns the length of the buffer, measured in bytes. All positions are indexed from zero.
Returns:
- Type
- number
-
setBuffer(pos, b, offset, len) → {Buffer}
-
Sets the bytes at position
posin the Buffer to the bytes represented by theBuffer bon the givenoffsetandlen.The buffer will expand as necessary to accommodate any value written.
Parameters:
Name Type Description posnumber bBuffer offsetnumber lennumber Returns:
- Type
- Buffer
-
setByte(pos, b) → {Buffer}
-
Sets the
byteat positionposin the Buffer to the valueb.The buffer will expand as necessary to accommodate any value written.
Parameters:
Name Type Description posnumber bnumber Returns:
- Type
- Buffer
-
setDouble(pos, d) → {Buffer}
-
Sets the
doubleat positionposin the Buffer to the valued.The buffer will expand as necessary to accommodate any value written.
Parameters:
Name Type Description posnumber dnumber Returns:
- Type
- Buffer
-
setFloat(pos, f) → {Buffer}
-
Sets the
floatat positionposin the Buffer to the valuef.The buffer will expand as necessary to accommodate any value written.
Parameters:
Name Type Description posnumber fnumber Returns:
- Type
- Buffer
-
setInt(pos, i) → {Buffer}
-
Sets the
intat positionposin the Buffer to the valuei.The buffer will expand as necessary to accommodate any value written.
Parameters:
Name Type Description posnumber inumber Returns:
- Type
- Buffer
-
setLong(pos, l) → {Buffer}
-
Sets the
longat positionposin the Buffer to the valuel.The buffer will expand as necessary to accommodate any value written.
Parameters:
Name Type Description posnumber lnumber Returns:
- Type
- Buffer
-
setShort(pos, s) → {Buffer}
-
Sets the
shortat positionposin the Buffer to the values.The buffer will expand as necessary to accommodate any value written.
Parameters:
Name Type Description posnumber snumber Returns:
- Type
- Buffer
-
setString(pos, str, enc) → {Buffer}
-
Sets the bytes at position
posin the Buffer to the value ofstrencoded in encodingenc.The buffer will expand as necessary to accommodate any value written.
Parameters:
Name Type Description posnumber strstring encstring Returns:
- Type
- Buffer
-
setUnsignedByte(pos, b) → {Buffer}
-
Sets the unsigned
byteat positionposin the Buffer to the valueb.The buffer will expand as necessary to accommodate any value written.
Parameters:
Name Type Description posnumber bnumber Returns:
- Type
- Buffer
-
setUnsignedInt(pos, i) → {Buffer}
-
Sets the unsigned
intat positionposin the Buffer to the valuei.The buffer will expand as necessary to accommodate any value written.
Parameters:
Name Type Description posnumber inumber Returns:
- Type
- Buffer
-
setUnsignedShort(pos, s) → {Buffer}
-
Sets the unsigned
shortat positionposin the Buffer to the values.The buffer will expand as necessary to accommodate any value written.
Parameters:
Name Type Description posnumber snumber Returns:
- Type
- Buffer
-
slice(start, end) → {Buffer}
-
Returns a slice of this buffer. Modifying the content of the returned buffer or this buffer affects each other's content while they maintain separate indexes and marks.
Parameters:
Name Type Description startnumber endnumber Returns:
- Type
- Buffer
-
toString(enc) → {string}
-
Returns a
Stringrepresentation of the Buffer with the encoding specified byencParameters:
Name Type Description encstring Returns:
- Type
- string