@@ -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.
@@ -482,9 +490,10 @@ Returns the byte length of a string when encoded using `encoding`.
482490This is not the same as [ ` String.prototype.length ` ] [ ] , which does not account
483491for the encoding that is used to convert the string into bytes.
484492
485- For ` 'base64' ` and ` 'hex' ` , this function assumes valid input. For strings that
486- contain non-base64/hex-encoded data (e.g. whitespace), the return value might be
487- greater than the length of a ` Buffer ` created from the string.
493+ For ` 'base64' ` , ` 'base64url' ` , and ` 'hex' ` , this function assumes valid input.
494+ For strings that contain non-base64/hex-encoded data (e.g. whitespace), the
495+ return value might be greater than the length of a ` Buffer ` created from the
496+ string.
488497
489498``` js
490499const str = ' \u00bd + \u00bc = \u00be ' ;
@@ -3418,6 +3427,7 @@ introducing security vulnerabilities into an application.
34183427[ `buffer.constants.MAX_STRING_LENGTH` ] : #buffer_buffer_constants_max_string_length
34193428[ `buffer.kMaxLength` ] : #buffer_buffer_kmaxlength
34203429[ `util.inspect()` ] : util.md#util_util_inspect_object_options
3430+ [ base64url ] : https://tools.ietf.org/html/rfc4648#section-5
34213431[ binary strings ] : https://developer.mozilla.org/en-US/docs/Web/API/DOMString/Binary
34223432[ endianness ] : https://en.wikipedia.org/wiki/Endianness
34233433[ iterator ] : https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Iteration_protocols
0 commit comments