0
0
Node.jsframework~5 mins

Reading and writing buffer data in Node.js - Cheat Sheet & Quick Revision

Choose your learning style9 modes available
Recall & Review
beginner
What is a Buffer in Node.js?
A Buffer is a special object in Node.js used to store raw binary data. It allows you to work with streams of bytes directly, like reading files or network data.
Click to reveal answer
beginner
How do you create a Buffer from a string in Node.js?
Use Buffer.from('your string') to create a Buffer containing the bytes of the string.
Click to reveal answer
intermediate
Which method reads an unsigned 8-bit integer from a Buffer at a specific offset?
The method buffer.readUInt8(offset) reads an unsigned 8-bit integer from the Buffer at the given offset.
Click to reveal answer
intermediate
How do you write a 16-bit unsigned integer to a Buffer at a specific offset?
Use buffer.writeUInt16LE(value, offset) to write a 16-bit unsigned integer in little-endian format at the offset.
Click to reveal answer
advanced
Why is it important to specify endianness when reading or writing multi-byte values in a Buffer?
Endianness determines byte order. Specifying it ensures data is interpreted correctly across different systems, preventing errors in reading or writing multi-byte numbers.
Click to reveal answer
Which method creates a Buffer from a string in Node.js?
Anew Buffer('text')
BBuffer.from('text')
CBuffer.create('text')
DBuffer.string('text')
What does buffer.readUInt8(0) return?
AAn unsigned 8-bit integer from the start of the buffer
BA signed 8-bit integer from the start of the buffer
CA string from the buffer
DThe length of the buffer
Which method writes a 32-bit unsigned integer in little-endian format to a Buffer?
Abuffer.writeUInt32LE(value, offset)
Bbuffer.writeUInt32BE(value, offset)
Cbuffer.writeInt32LE(value, offset)
Dbuffer.writeInt32BE(value, offset)
What is the default encoding when converting a Buffer to a string using buffer.toString()?
Ahex
Bascii
Cbase64
Dutf8
Why should you be careful with the offset when reading or writing Buffer data?
AOffset controls the Buffer size
BBecause offset changes the encoding
CTo avoid reading or writing outside the Buffer bounds causing errors
DOffset is only used for strings
Explain how to read and write numeric data using Node.js Buffers. Include how to handle byte order.
Think about how bytes are stored and accessed in memory.
You got /4 concepts.
    Describe how to convert a string to a Buffer and back to a string in Node.js.
    Consider how text is stored as bytes.
    You got /4 concepts.