> ## Documentation Index
> Fetch the complete documentation index at: https://bun.zhcndoc.com/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={"theme":{"light":"github-light","dark":"dracula"}}
const buf = Buffer.from("hello");
const str = buf.toString();
// => "hello"
```

***

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

```ts theme={"theme":{"light":"github-light","dark":"dracula"}}
const buf = Buffer.from("hello world!");
const str = buf.toString("utf8", 0, 5);
// => "hello"
```

***

请参见 [文档 > API > 二进制数据](/runtime/binary-data#conversion) ，了解使用 Bun 操作二进制数据的完整文档。
