Skip to content

Commit afd02d0

Browse files
gioraguttLinkgoron
authored andcommitted
doc: improve 'hex' Buffer decoding description and examples
PR-URL: nodejs#41598 Fixes: nodejs#41594 Reviewed-By: Benjamin Gruenbaum <[email protected]> Reviewed-By: Antoine du Hamel <[email protected]> Reviewed-By: Tobias Nießen <[email protected]> Reviewed-By: Anna Henningsen <[email protected]> Reviewed-By: Mestery <[email protected]> Reviewed-By: Luigi Pinca <[email protected]> Reviewed-By: Rich Trott <[email protected]>
1 parent eadb217 commit afd02d0

File tree

1 file changed

+6
-6
lines changed

1 file changed

+6
-6
lines changed

doc/api/buffer.md

+6-6
Original file line numberDiff line numberDiff line change
@@ -175,8 +175,8 @@ string into a `Buffer` as decoding.
175175
encoding a `Buffer` to a string, this encoding will omit padding.
176176

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

181181
The following legacy character encodings are also supported:
182182

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

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

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

211211
Buffer.from('1634', 'hex');
@@ -215,11 +215,11 @@ Buffer.from('1634', 'hex');
215215
```cjs
216216
const { Buffer } = require('buffer');
217217

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

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

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

0 commit comments

Comments
 (0)