buffer.btoa(data)


稳定性: 3 - 过时。请改用 buf.toString('base64')

  • data <any> 一个 ASCII(Latin1)字符串。

使用 Latin-1(ISO-8859)将字符串解码为字节,然后使用 Base64 将这些字节编码为字符串。

【Decodes a string into bytes using Latin-1 (ISO-8859), and encodes those bytes into a string using Base64.】

data 可以是任何可以被强制转换为字符串的 JavaScript 值。

【The data may be any JavaScript-value that can be coerced into a string.】

此函数仅为兼容旧版 Web 平台 API 而提供,不应在新代码中使用,因为它们使用字符串来表示二进制数据,并且早于 JavaScript 中引入的类型化数组。 对于使用 Node.js API 运行的代码,应使用 Buffer.from(str, 'base64')buf.toString('base64') 在 Base64 编码字符串与二进制数据之间进行转换。