將 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"
請參閱二進位制資料。