將 Buffer 轉換為字串Buffer 類提供了一個 .toString() 方法,可將 Buffer 轉換為字串。 TypeScript複製const buf = Buffer.from("hello"); const str = buf.toString(); // => "hello" 你可以選擇指定編碼和位元組範圍。 TypeScript複製const buf = Buffer.from("hello world!"); const str = buf.toString("utf8", 0, 5); // => "hello" 請參閱二進位制資料。