运行时包管理器打包器测试运行器代码检查格式化指南参考博客反馈

将 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"

请参阅二进制数据。