String decoder

StringDecoder.end()

Finishes decoding with optional final bytes. Incomplete UTF-8 at end is replaced; if malformed data must be rejected, use a strict decoding policy instead. Tested on Node.js 22.16.0. Example output (one line per entry): ["true", "true"].

Formal Syntax & Structure

nodejs syntaxnodejs
decoder.end([buffer])

Parameters & Attributes

NameTypeDescription
bufferBuffer | TypedArray | DataViewFinal bytes.

Return Value

string

Remaining decoded text.

Working Example

Example Snippetnodejs
import { StringDecoder } from 'node:string_decoder';const d = new StringDecoder('utf8');console.log(d.write(Buffer.from([0xc3])) === '');console.log(d.end() === '\uFFFD');
Node.js Reference