> ## Documentation Index
> Fetch the complete documentation index at: https://bun.ll1025.cn/llms.txt
> Use this file to discover all available pages before exploring further.

# 将 Buffer 转换为字符串

[`Buffer`](https://nodejs.org/api/buffer.html) 类提供了 `.toString()` 方法，用于将 `Buffer` 转换为字符串。

```ts theme={null}
const buf = Buffer.from("hello");
const str = buf.toString();
// => "hello"
```

***

你可以选择指定编码和字节范围。

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

***

参见 [二进制数据](/runtime/binary-data#conversion)。
