Skip to content

Commit 5f0a017

Browse files
gioraguttdanielleadams
authored andcommitted
doc: improve 'hex' Buffer decoding description and examples
PR-URL: #41598 Fixes: #41594 Reviewed-By: Benjamin Gruenbaum <benjamingr@gmail.com> Reviewed-By: Antoine du Hamel <duhamelantoine1995@gmail.com> Reviewed-By: Tobias Nießen <tniessen@tnie.de> Reviewed-By: Anna Henningsen <anna@addaleax.net> Reviewed-By: Mestery <mestery@protonmail.com> Reviewed-By: Luigi Pinca <luigipinca@gmail.com> Reviewed-By: Rich Trott <rtrott@gmail.com>
1 parent 0f3287d commit 5f0a017

File tree

1 file changed

+6
-6
lines changed

1 file changed

+6
-6
lines changed

doc/api/buffer.md

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -173,8 +173,8 @@ string into a `Buffer` as decoding.
173173
encoding a `Buffer` to a string, this encoding will omit padding.
174174

175175
* `'hex'`: Encode each byte as two hexadecimal characters. Data truncation
176-
may occur when decoding strings that do exclusively contain valid hexadecimal
177-
characters. See below for an example.
176+
may occur when decoding strings that do not exclusively consist of an even
177+
number of hexadecimal characters. See below for an example.
178178

179179
The following legacy character encodings are also supported:
180180

@@ -199,11 +199,11 @@ The following legacy character encodings are also supported:
199199
```mjs
200200
import { Buffer } from 'buffer';
201201

202-
Buffer.from('1ag', 'hex');
202+
Buffer.from('1ag123', 'hex');
203203
// Prints <Buffer 1a>, data truncated when first non-hexadecimal value
204204
// ('g') encountered.
205205

206-
Buffer.from('1a7g', 'hex');
206+
Buffer.from('1a7', 'hex');
207207
// Prints <Buffer 1a>, data truncated when data ends in single digit ('7').
208208

209209
Buffer.from('1634', 'hex');
@@ -213,11 +213,11 @@ Buffer.from('1634', 'hex');
213213
```cjs
214214
const { Buffer } = require('buffer');
215215

216-
Buffer.from('1ag', 'hex');
216+
Buffer.from('1ag123', 'hex');
217217
// Prints <Buffer 1a>, data truncated when first non-hexadecimal value
218218
// ('g') encountered.
219219

220-
Buffer.from('1a7g', 'hex');
220+
Buffer.from('1a7', 'hex');
221221
// Prints <Buffer 1a>, data truncated when data ends in single digit ('7').
222222

223223
Buffer.from('1634', 'hex');

0 commit comments

Comments
 (0)