Skip to content

Buffer 類提供了一個內置的 .toString() 方法,用於將 Buffer 轉換為字符串。

ts
const buf = Buffer.from("hello");
const str = buf.toString();
// => "hello"

你可以選擇指定編碼和字節范圍。

ts
const buf = Buffer.from("hello world!");
const str = buf.toString("utf8", 0, 5);
// => "hello"

有關使用 Bun 操作二進制數據的完整文檔,請參閱 文檔 > API > 二進制數據

Bun學習網由www.bunjs.com.cn整理維護