Buffer
buffer.transcode()
Converts between supported character encodings. Unrepresentable characters may be substituted, so this is not guaranteed lossless. Tested on Node.js 22.16.0. Example output (one line per entry): ["e9"].
Formal Syntax & Structure
nodejs syntaxnodejs
transcode(source, fromEnc, toEnc)Parameters & Attributes
| Name | Type | Description |
|---|---|---|
| source | Buffer | Uint8Array | Source bytes. |
| fromEnc | string | Source encoding. |
| toEnc | string | Destination encoding. |
Return Value
Buffer
Converted bytes.
Working Example
Example Snippetnodejs
import { transcode } from 'node:buffer';console.log(transcode(Buffer.from('é'), 'utf8', 'latin1').toString('hex'));