Uint8Array.prototype.toBase64() 和 Uint8Array.fromBase64() 来编码和解码 base64 数据。这些 API 直接操作字节,因此比旧的 btoa() 和 atob() 全局函数更适合处理二进制数据。
TextEncoder 和 TextDecoder 转换为 UTF-8 字节。
Buffer 继承自 Uint8Array,因此可以使用 toBase64() 编码缓冲区,并传递给接受 Uint8Array 的 API。Buffer 还提供 Node.js 兼容的 base64 解码:Buffer.from(encoded, "base64")。
参见 Web API。