Methods of writing from Buffer objects
Method Syntax Description
Writes data into the buffer
buffer.write(string,
Write with [offset], [length],
starting at the specified offset
write() [encoding]) and for the given length using
the specified encoding.
Write with buffer[offset] = value
Sets the byte at the specified
Index offset to the given value.
Fills the buffer with the
buffer.fill(value,
Fill the Buffer [offset], [end]) specified value from the offset
to the end index.
Writes integer or float values
Write writeInt8(value, offset, [noAssert]) into the buffer at the specified
Integers/Floats writeInt16LE(value, offset, [noAssert]) offset, using little-endian or
big-endian format.
Simple and Short Example for Writing to a Buffer
Output for the Example:
add some text
add some more text
add some more text+
Methods of reading from Buffer objects
Method Description
buffer.toString([encoding], [start], Converts part of the buffer to a string from the
[end]) start to end index.
stringDecoder.write(buffer)
Decodes and returns a string version of the
buffer.
buffer[offset]
Retrieves the octet value at the specified
offset in the buffer.
readInt8(offset, [noAssert])
Reads an 8-bit signed integer from the
specified offset.
readInt16LE(offset, [noAssert])
Reads a 16-bit signed integer in little-endian
format from the offset.
readInt16BE(offset, [noAssert])
Reads a 16-bit signed integer in big-endian
format from the offset.
Output for the Example:
Hello World!
Hello
Determining Buffer Length
Copying Buffers
Slicing Buffers
Concatenating Buffers