0% found this document useful (0 votes)
176 views5 pages

Handling Data Io

The document outlines methods for writing to and reading from Buffer objects in programming, detailing various functions such as write(), fill(), and readInt8(). It includes syntax and descriptions for each method, as well as examples of output. Additionally, it mentions operations like determining buffer length, copying, slicing, and concatenating buffers.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
176 views5 pages

Handling Data Io

The document outlines methods for writing to and reading from Buffer objects in programming, detailing various functions such as write(), fill(), and readInt8(). It includes syntax and descriptions for each method, as well as examples of output. Additionally, it mentions operations like determining buffer length, copying, slicing, and concatenating buffers.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd

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

You might also like