diff options
author | James M Snell <jasnell@gmail.com> | 2021-03-17 21:00:57 +0300 |
---|---|---|
committer | James M Snell <jasnell@gmail.com> | 2021-03-18 22:04:00 +0300 |
commit | 08770bc24a264959bb17ee9bd06f39bd3087fa0e (patch) | |
tree | 3d9390e9834ea238898e1634677ae35691a4de98 /doc/api/buffer.md | |
parent | a2fdef0e28a98adad6b15034ff0888661c324b26 (diff) |
buffer: implement btoa and atob
Signed-off-by: James M Snell <jasnell@gmail.com>
PR-URL: https://github.com/nodejs/node/pull/37529
Fixes: https://github.com/nodejs/node/issues/3462
Reviewed-By: Anna Henningsen <anna@addaleax.net>
Reviewed-By: Matteo Collina <matteo.collina@gmail.com>
Diffstat (limited to 'doc/api/buffer.md')
-rw-r--r-- | doc/api/buffer.md | 38 |
1 files changed, 38 insertions, 0 deletions
diff --git a/doc/api/buffer.md b/doc/api/buffer.md index 764762c986f..f31b8b298b0 100644 --- a/doc/api/buffer.md +++ b/doc/api/buffer.md @@ -3277,6 +3277,44 @@ While, the `Buffer` object is available as a global, there are additional `Buffer`-related APIs that are available only via the `buffer` module accessed using `require('buffer')`. +### `buffer.atob(data)` +<!-- YAML +added: REPLACEME +--> + +* `data` {any} The Base64-encoded input string. + +Decodes a string of Base64-encoded data into bytes, and encodes those bytes +into a string using Latin-1 (ISO-8859-1). + +The `data` may be any JavaScript-value that can be coerced into a string. + +**This function is only provided for compatibility with legacy web platform APIs +and should never be used in new code, because they use strings to represent +binary data and predate the introduction of typed arrays in JavaScript. +For code running using Node.js APIs, converting between base64-encoded strings +and binary data should be performed using `Buffer.from(str, 'base64')` and +`buf.toString('base64')`.** + +### `buffer.btoa(data)` +<!-- YAML +added: REPLACEME +--> + +* `data` {any} An ASCII (Latin1) string. + +Decodes a string into bytes using Latin-1 (ISO-8859), and encodes those bytes +into a string using Base64. + +The `data` may be any JavaScript-value that can be coerced into a string. + +**This function is only provided for compatibility with legacy web platform APIs +and should never be used in new code, because they use strings to represent +binary data and predate the introduction of typed arrays in JavaScript. +For code running using Node.js APIs, converting between base64-encoded strings +and binary data should be performed using `Buffer.from(str, 'base64')` and +`buf.toString('base64')`.** + ### `buffer.INSPECT_MAX_BYTES` <!-- YAML added: v0.5.4 |