Skip to content

Commit

Permalink
doc: explain hex encoding in Buffer API
Browse files Browse the repository at this point in the history
fixes: #29786
refs: #29792
refs: #24491

PR-URL: #31352
Fixes: #29786
Refs: #29792
Refs: #24491
Reviewed-By: Anna Henningsen <[email protected]>
Reviewed-By: Rich Trott <[email protected]>
  • Loading branch information
HarshithaKP authored and codebytere committed Mar 17, 2020
1 parent ff8f0bc commit d944fa7
Showing 1 changed file with 14 additions and 1 deletion.
15 changes: 14 additions & 1 deletion doc/api/buffer.md
Original file line number Diff line number Diff line change
Expand Up @@ -203,7 +203,20 @@ The character encodings currently supported by Node.js include:

* `'binary'`: Alias for `'latin1'`.

* `'hex'`: Encode each byte as two hexadecimal characters.
* `'hex'`: Encode each byte as two hexadecimal characters. Data truncation
may occur for unsanitized input. For example:

```js
Buffer.from('1ag', 'hex');
// Prints <Buffer 1a>, data truncated when first non-hexadecimal value
// ('g') encountered.

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

Buffer.from('1634', 'hex');
// Prints <Buffer 16 34>, all data represented.
```

Modern Web browsers follow the [WHATWG Encoding Standard][] which aliases
both `'latin1'` and `'ISO-8859-1'` to `'win-1252'`. This means that while doing
Expand Down

0 comments on commit d944fa7

Please sign in to comment.