String decoder
new StringDecoder()
Creates a stateful decoder that retains incomplete encoded characters between chunks. Use one decoder per independent byte stream. Tested on Node.js 22.16.0. Example output (one line per entry): ["caf\u00e9"].
Formal Syntax & Structure
nodejs syntaxnodejs
new StringDecoder([encoding])Parameters & Attributes
| Name | Type | Description |
|---|---|---|
| encoding | string | Character encoding, default UTF-8. |
Return Value
StringDecoder
Stateful decoder.
Working Example
Example Snippetnodejs
import { StringDecoder } from 'node:string_decoder';const d = new StringDecoder('utf8');const b = Buffer.from('café');console.log(d.write(b.subarray(0, 4)) + d.end(b.subarray(4)));