@@ -50,6 +50,9 @@ const buf7 = Buffer.from('tést', 'latin1');
5050## Buffers and character encodings
5151<!-- YAML
5252changes:
53+ - version: REPLACEME
54+ pr-url: https://github.com/nodejs/node/pull/36952
55+ description: Introduced `base64url` encoding.
5356 - version: v6.4.0
5457 pr-url: https://github.com/nodejs/node/pull/7111
5558 description: Introduced `latin1` as an alias for `binary`.
@@ -106,6 +109,11 @@ string into a `Buffer` as decoding.
106109 specified in [ RFC 4648, Section 5] [ ] . Whitespace characters such as spaces,
107110 tabs, and new lines contained within the base64-encoded string are ignored.
108111
112+ * ` 'base64url' ` : [ base64url] [ ] encoding as specified in
113+ [ RFC 4648, Section 5] [ ] . When creating a ` Buffer ` from a string, this
114+ encoding will also correctly accept regular base64-encoded strings. When
115+ encoding a ` Buffer ` to a string, this encoding will omit padding.
116+
109117* ` 'hex' ` : Encode each byte as two hexadecimal characters. Data truncation
110118 may occur when decoding strings that do exclusively contain valid hexadecimal
111119 characters. See below for an example.
@@ -469,9 +477,10 @@ Returns the byte length of a string when encoded using `encoding`.
469477This is not the same as [ ` String.prototype.length ` ] [ ] , which does not account
470478for the encoding that is used to convert the string into bytes.
471479
472- For ` 'base64' ` and ` 'hex' ` , this function assumes valid input. For strings that
473- contain non-base64/hex-encoded data (e.g. whitespace), the return value might be
474- greater than the length of a ` Buffer ` created from the string.
480+ For ` 'base64' ` , ` 'base64url' ` , and ` 'hex' ` , this function assumes valid input.
481+ For strings that contain non-base64/hex-encoded data (e.g. whitespace), the
482+ return value might be greater than the length of a ` Buffer ` created from the
483+ string.
475484
476485``` js
477486const str = ' \u00bd + \u00bc = \u00be ' ;
@@ -3427,6 +3436,7 @@ introducing security vulnerabilities into an application.
34273436[ `buffer.kMaxLength` ] : #buffer_buffer_kmaxlength
34283437[ `util.inspect()` ] : util.md#util_util_inspect_object_options
34293438[ `v8::TypedArray::kMaxLength` ] : https://v8.github.io/api/head/classv8_1_1TypedArray.html#a54a48f4373da0850663c4393d843b9b0
3439+ [ base64url ] : https://tools.ietf.org/html/rfc4648#section-5
34303440[ binary strings ] : https://developer.mozilla.org/en-US/docs/Web/API/DOMString/Binary
34313441[ endianness ] : https://en.wikipedia.org/wiki/Endianness
34323442[ iterator ] : https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Iteration_protocols
0 commit comments