String decoder

StringDecoder.write()

Decodes a byte chunk and retains incomplete trailing sequences for later writes or end. Returns text, possibly empty. Not a strict malformed-input validator.

Formal Syntax & Structure

nodejs syntaxnodejs
decoder.write(buffer)

Parameters & Attributes

NameTypeDescription
bufferBuffer | TypedArray | DataViewBytes to decode.

Return Value

string

Text decoded so far.

Working Example

Example Snippetnodejs
import { StringDecoder } from "node:string_decoder";import { Buffer } from "node:buffer";const decoder = new StringDecoder("utf8");console.log(decoder.write(Buffer.from("book")) + decoder.end());
Node.js Reference