Back to the Catalog
nodejs
javascript

Node.js Buffers & Binary Data

12 questions

How Buffer, Uint8Array, ArrayBuffer, and DataView fit together; UTF-8 / hex / base64 encodings; byte order; which operations share memory versus copy; and why turning binary into a string destroys it. Every answer is verified by running the code in Node.

Questions

  1. Not answered. Buffer is a subclass of which built-in JavaScript typed array?
  2. Not answered. What is an ArrayBuffer, and how do you read the bytes inside it?
  3. Not answered. What is new Uint32Array(4).byteLength?
  4. Not answered. Which statements about Buffer versus Uint8Array are correct?
  5. Not answered. How many bytes is the string café in UTF-8?
  6. Not answered. What does Buffer.from('SGVsbG8=', 'base64').toString('utf8') return?
  7. Not answered. Reading a binary file, you write let data = '' then stream.on('data', c => data += c). Why is the result corrupted?
  8. Not answered. Decoding a UTF-8 stream as chunk.toString() per chunk sometimes yields . Why?
  9. Not answered. What is [...new Uint8Array([256, -1, 300])]?
  10. Not answered. The bytes 00 00 00 01 read as a 32-bit integer give 1 one way and 16777216 the other. What causes the difference?
  11. Not answered. Which of these operations return something that shares memory with the source rather than copying it?
  12. Not answered. What is the difference between Buffer.alloc(1024) and Buffer.allocUnsafe(1024)?