diff options
author | Filip Skokan <panva.ip@gmail.com> | 2021-01-15 23:01:28 +0300 |
---|---|---|
committer | Antoine du Hamel <duhamelantoine1995@gmail.com> | 2021-01-18 14:08:20 +0300 |
commit | f8ab632d56ea15c78b1dc5db1624109a2bf7b69b (patch) | |
tree | 248839d4a4ed92d3fc8e4b0ca8a770744ab0cc8f /doc/api/buffer.md | |
parent | 9e7d1a1c24888ee9f1290579c7170b1eb094d609 (diff) |
buffer: add base64url encoding option
PR-URL: https://github.com/nodejs/node/pull/36952
Reviewed-By: James M Snell <jasnell@gmail.com>
Reviewed-By: Antoine du Hamel <duhamelantoine1995@gmail.com>
Reviewed-By: Rich Trott <rtrott@gmail.com>
Reviewed-By: Anna Henningsen <anna@addaleax.net>
Diffstat (limited to 'doc/api/buffer.md')
-rw-r--r-- | doc/api/buffer.md | 16 |
1 files changed, 13 insertions, 3 deletions
diff --git a/doc/api/buffer.md b/doc/api/buffer.md index 765aa2dd088..cebb9b7b975 100644 --- a/doc/api/buffer.md +++ b/doc/api/buffer.md @@ -50,6 +50,9 @@ const buf7 = Buffer.from('tést', 'latin1'); ## Buffers and character encodings <!-- YAML changes: + - version: REPLACEME + pr-url: https://github.com/nodejs/node/pull/36952 + description: Introduced `base64url` encoding. - version: v6.4.0 pr-url: https://github.com/nodejs/node/pull/7111 description: Introduced `latin1` as an alias for `binary`. @@ -106,6 +109,11 @@ string into a `Buffer` as decoding. specified in [RFC 4648, Section 5][]. Whitespace characters such as spaces, tabs, and new lines contained within the base64-encoded string are ignored. +* `'base64url'`: [base64url][] encoding as specified in + [RFC 4648, Section 5][]. When creating a `Buffer` from a string, this + encoding will also correctly accept regular base64-encoded strings. When + encoding a `Buffer` to a string, this encoding will omit padding. + * `'hex'`: Encode each byte as two hexadecimal characters. Data truncation may occur when decoding strings that do exclusively contain valid hexadecimal characters. See below for an example. @@ -482,9 +490,10 @@ Returns the byte length of a string when encoded using `encoding`. This is not the same as [`String.prototype.length`][], which does not account for the encoding that is used to convert the string into bytes. -For `'base64'` and `'hex'`, this function assumes valid input. For strings that -contain non-base64/hex-encoded data (e.g. whitespace), the return value might be -greater than the length of a `Buffer` created from the string. +For `'base64'`, `'base64url'`, and `'hex'`, this function assumes valid input. +For strings that contain non-base64/hex-encoded data (e.g. whitespace), the +return value might be greater than the length of a `Buffer` created from the +string. ```js const str = '\u00bd + \u00bc = \u00be'; @@ -3418,6 +3427,7 @@ introducing security vulnerabilities into an application. [`buffer.constants.MAX_STRING_LENGTH`]: #buffer_buffer_constants_max_string_length [`buffer.kMaxLength`]: #buffer_buffer_kmaxlength [`util.inspect()`]: util.md#util_util_inspect_object_options +[base64url]: https://tools.ietf.org/html/rfc4648#section-5 [binary strings]: https://developer.mozilla.org/en-US/docs/Web/API/DOMString/Binary [endianness]: https://en.wikipedia.org/wiki/Endianness [iterator]: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Iteration_protocols |