Skip to content

Buffer クラスは、Buffer を文字列に変換する組み込みの .toString() メソッドを提供しています。

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 by www.bunjs.com.cn 編集