将 Uint8Array 转换为字符串
Bun 实现了符合 Web 标准的 TextDecoder 类,用于将 Uint8Array 等二进制数据类型转换为字符串。
TypeScript
const arr = new Uint8Array([104, 101, 108, 108, 111]);
const decoder = new TextDecoder();
const str = decoder.decode(arr);
// => "hello"
请参阅二进制数据。
Bun 实现了符合 Web 标准的 TextDecoder 类,用于将 Uint8Array 等二进制数据类型转换为字符串。
const arr = new Uint8Array([104, 101, 108, 108, 111]);
const decoder = new TextDecoder();
const str = decoder.decode(arr);
// => "hello"
请参阅二进制数据。