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
Buffer
starting at theoffset
usinglen
to the end of this Buffer. The buffer will expand as necessary to accommodate any bytes written.Returns a reference to
this
so multiple operations can be appended together.Parameters:
Name Type Description buff
Buffer offset
number len
number Returns:
- Type
- Buffer
-
appendByte(b) → {Buffer}
-
Appends the specified
byte
to the end of the Buffer. The buffer will expand as necessary to accommodate any bytes written.Returns a reference to
this
so multiple operations can be appended together.Parameters:
Name Type Description b
number Returns:
- Type
- Buffer
-
appendDouble(d) → {Buffer}
-
Appends the specified
double
to the end of the Buffer. The buffer will expand as necessary to accommodate any bytes written.Returns a reference to
this
so multiple operations can be appended together.Parameters:
Name Type Description d
number Returns:
- Type
- Buffer
-
appendFloat(f) → {Buffer}
-
Appends the specified
float
to the end of the Buffer. The buffer will expand as necessary to accommodate any bytes written.Returns a reference to
this
so multiple operations can be appended together.Parameters:
Name Type Description f
number Returns:
- Type
- Buffer
-
appendInt(i) → {Buffer}
-
Appends the specified
int
to the end of the Buffer. The buffer will expand as necessary to accommodate any bytes written.Returns a reference to
this
so multiple operations can be appended together.Parameters:
Name Type Description i
number Returns:
- Type
- Buffer
-
appendLong(l) → {Buffer}
-
Appends the specified
long
to the end of the Buffer. The buffer will expand as necessary to accommodate any bytes written.Returns a reference to
this
so multiple operations can be appended together.Parameters:
Name Type Description l
number Returns:
- Type
- Buffer
-
appendShort(s) → {Buffer}
-
Appends the specified
short
to the end of the Buffer.The buffer will expand as necessary to accommodate any bytes written.Returns a reference to
this
so multiple operations can be appended together.Parameters:
Name Type Description s
number Returns:
- Type
- Buffer
-
appendString(str, enc) → {Buffer}
-
Appends the specified
String
to 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
this
so multiple operations can be appended together.Parameters:
Name Type Description str
string enc
string Returns:
- Type
- Buffer
-
appendUnsignedByte(b) → {Buffer}
-
Appends the specified unsigned
byte
to the end of the Buffer. The buffer will expand as necessary to accommodate any bytes written.Returns a reference to
this
so multiple operations can be appended together.Parameters:
Name Type Description b
number Returns:
- Type
- Buffer
-
appendUnsignedInt(i) → {Buffer}
-
Appends the specified unsigned
int
to the end of the Buffer. The buffer will expand as necessary to accommodate any bytes written.Returns a reference to
this
so multiple operations can be appended together.Parameters:
Name Type Description i
number Returns:
- Type
- Buffer
-
appendUnsignedShort(s) → {Buffer}
-
Appends the specified unsigned
short
to the end of the Buffer.The buffer will expand as necessary to accommodate any bytes written.Returns a reference to
this
so multiple operations can be appended together.Parameters:
Name Type Description s
number 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
start
and ending at positionend - 1
Parameters:
Name Type Description start
number end
number Returns:
- Type
- Buffer
-
getByte(pos) → {number}
-
Returns the
byte
at positionpos
in the Buffer.Parameters:
Name Type Description pos
number Returns:
- Type
- number
-
getDouble(pos) → {number}
-
Returns the
double
at positionpos
in the Buffer.Parameters:
Name Type Description pos
number Returns:
- Type
- number
-
getFloat(pos) → {number}
-
Returns the
float
at positionpos
in the Buffer.Parameters:
Name Type Description pos
number Returns:
- Type
- number
-
getInt(pos) → {number}
-
Returns the
int
at positionpos
in the Buffer.Parameters:
Name Type Description pos
number Returns:
- Type
- number
-
getLong(pos) → {number}
-
Returns the
long
at positionpos
in the Buffer.Parameters:
Name Type Description pos
number Returns:
- Type
- number
-
getShort(pos) → {number}
-
Returns the
short
at positionpos
in the Buffer.Parameters:
Name Type Description pos
number Returns:
- Type
- number
-
getString(start, end, enc) → {string}
-
Returns a copy of a sub-sequence the Buffer as a
String
starting at positionstart
and ending at positionend - 1
interpreted as a String in the specified encodingParameters:
Name Type Description start
number end
number enc
string Returns:
- Type
- string
-
getUnsignedByte(pos) → {number}
-
Returns the unsigned
byte
at positionpos
in the Buffer, as ashort
.Parameters:
Name Type Description pos
number Returns:
- Type
- number
-
getUnsignedInt(pos) → {number}
-
Returns the unsigned
int
at positionpos
in the Buffer, as along
.Parameters:
Name Type Description pos
number Returns:
- Type
- number
-
getUnsignedShort(pos) → {number}
-
Returns the unsigned
short
at positionpos
in the Buffer, as anint
.Parameters:
Name Type Description pos
number 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
pos
in the Buffer to the bytes represented by theBuffer b
on the givenoffset
andlen
.The buffer will expand as necessary to accommodate any value written.
Parameters:
Name Type Description pos
number b
Buffer offset
number len
number Returns:
- Type
- Buffer
-
setByte(pos, b) → {Buffer}
-
Sets the
byte
at positionpos
in the Buffer to the valueb
.The buffer will expand as necessary to accommodate any value written.
Parameters:
Name Type Description pos
number b
number Returns:
- Type
- Buffer
-
setDouble(pos, d) → {Buffer}
-
Sets the
double
at positionpos
in the Buffer to the valued
.The buffer will expand as necessary to accommodate any value written.
Parameters:
Name Type Description pos
number d
number Returns:
- Type
- Buffer
-
setFloat(pos, f) → {Buffer}
-
Sets the
float
at positionpos
in the Buffer to the valuef
.The buffer will expand as necessary to accommodate any value written.
Parameters:
Name Type Description pos
number f
number Returns:
- Type
- Buffer
-
setInt(pos, i) → {Buffer}
-
Sets the
int
at positionpos
in the Buffer to the valuei
.The buffer will expand as necessary to accommodate any value written.
Parameters:
Name Type Description pos
number i
number Returns:
- Type
- Buffer
-
setLong(pos, l) → {Buffer}
-
Sets the
long
at positionpos
in the Buffer to the valuel
.The buffer will expand as necessary to accommodate any value written.
Parameters:
Name Type Description pos
number l
number Returns:
- Type
- Buffer
-
setShort(pos, s) → {Buffer}
-
Sets the
short
at positionpos
in the Buffer to the values
.The buffer will expand as necessary to accommodate any value written.
Parameters:
Name Type Description pos
number s
number Returns:
- Type
- Buffer
-
setString(pos, str, enc) → {Buffer}
-
Sets the bytes at position
pos
in the Buffer to the value ofstr
encoded in encodingenc
.The buffer will expand as necessary to accommodate any value written.
Parameters:
Name Type Description pos
number str
string enc
string Returns:
- Type
- Buffer
-
setUnsignedByte(pos, b) → {Buffer}
-
Sets the unsigned
byte
at positionpos
in the Buffer to the valueb
.The buffer will expand as necessary to accommodate any value written.
Parameters:
Name Type Description pos
number b
number Returns:
- Type
- Buffer
-
setUnsignedInt(pos, i) → {Buffer}
-
Sets the unsigned
int
at positionpos
in the Buffer to the valuei
.The buffer will expand as necessary to accommodate any value written.
Parameters:
Name Type Description pos
number i
number Returns:
- Type
- Buffer
-
setUnsignedShort(pos, s) → {Buffer}
-
Sets the unsigned
short
at positionpos
in the Buffer to the values
.The buffer will expand as necessary to accommodate any value written.
Parameters:
Name Type Description pos
number s
number 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 start
number end
number Returns:
- Type
- Buffer
-
toString(enc) → {string}
-
Returns a
String
representation of the Buffer with the encoding specified byenc
Parameters:
Name Type Description enc
string Returns:
- Type
- string