textEncoder.encodeInto(src, dest)


UTF-8 会将 src 字符串编码到 dest Uint8Array 中,并返回一个包含已读取的 Unicode 代码单元和已写入的 UTF-8 字节的对象。

【UTF-8 encodes the src string to the dest Uint8Array and returns an object containing the read Unicode code units and written UTF-8 bytes.】

const encoder = new TextEncoder();
const src = 'this is some data';
const dest = new Uint8Array(10);
const { read, written } = encoder.encodeInto(src, dest);