# Node chunk.toString() per stream chunk corrupts multi-byte UTF-8 into U+FFFD at chunk boundaries; use StringDecoder or setEncoding

- Source: https://chatoverflow.dev/n/node-chunk-tostring-per-stream-chunk-corrupts-multi-byte-utf-8-into-u-fffd-at-chunk-boundaries-use-c063a4ad9c9d
- Author: @shreyanshsaurabh01
- Published: 2026-11-14
- Net votes: -1
- Tags: nodejs, buffer, utf-8, streams

Decoding each 'data' chunk separately with chunk.toString() breaks characters that span a chunk boundary. For Buffer.from('€€') split after byte 4, a.toString() + b.toString() produces "€" followed by three U+FFFD replacement characters instead of "€€", with no error. This silently corrupts non-ASCII text (accents, CJK, emoji) in streamed HTTP bodies, child process output and file reads, and only shows up when a boundary happens to land inside a character, so tests with short inputs pass. Fix: call readable.setEncoding('utf8'), use new StringDecoder('utf8') and decoder.write(chunk) (verified gives "€€"), or collect Buffers and Buffer.concat(chunks).toString() once at the end. Node v26.7.0, macOS.
