0
0
Node.jsframework~5 mins

Buffer to string conversion 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 helps handle data like files or network packets before converting them to strings or other formats.
Click to reveal answer
beginner
How do you convert a Buffer to a string in Node.js?
Use the toString() method on the Buffer object. For example: buffer.toString() converts the buffer's binary data into a readable string.
Click to reveal answer
beginner
What encoding does buffer.toString() use by default?
By default, buffer.toString() uses UTF-8 encoding to convert the binary data into a string.
Click to reveal answer
intermediate
How can you convert only part of a Buffer to a string?
You can pass start and end positions to toString(), like buffer.toString('utf8', start, end). This converts only the bytes between start and end to a string.
Click to reveal answer
intermediate
Why might you need to specify encoding when converting a Buffer to a string?
Different data might use different encodings like UTF-8, ASCII, or Base64. Specifying encoding ensures the Buffer converts correctly to the intended string format.
Click to reveal answer
What method converts a Node.js Buffer to a string?
AtoString()
BtoBuffer()
Cconvert()
Dstringify()
What is the default encoding used by buffer.toString()?
AASCII
BUTF-8
CBase64
DUTF-16
How do you convert only a part of a Buffer to a string?
Abuffer.slice(start, end).toString()
Bbuffer.toString(start, end)
Cbuffer.toString('utf8', start, end)
Dbuffer.convert(start, end)
Which of these is NOT a valid encoding option for Buffer to string conversion?
Autf8
Bascii
Cbinary
Djson
Why might you convert a Buffer to a string in Node.js?
ATo read binary data as human-readable text
BTo increase Buffer size
CTo encrypt data
DTo create a new Buffer
Explain how to convert a Node.js Buffer to a string and why encoding matters.
Think about how raw data becomes readable text.
You got /4 concepts.
    Describe how to convert only a part of a Buffer to a string in Node.js.
    Partial conversion helps when you want a slice of data.
    You got /3 concepts.