diff options
author | Harshitha KP <harshi46@in.ibm.com> | 2020-01-14 02:37:24 -0500 |
---|---|---|
committer | Shelley Vohr <shelley.vohr@gmail.com> | 2020-02-17 10:18:33 -0800 |
commit | 6055134db6882aa861f4f7986d39d4f436523c27 (patch) | |
tree | 878511fd10dbaa413fe4e1529b36787935852205 /doc | |
parent | 6833f62e9d0705362cf8bdaafe80733d509f6c32 (diff) | |
download | node-new-6055134db6882aa861f4f7986d39d4f436523c27.tar.gz |
doc: explain `hex` encoding in Buffer API
fixes: https://github.com/nodejs/node/issues/29786
refs: https://github.com/nodejs/node/pull/29792
refs: https://github.com/nodejs/node/issues/24491
PR-URL: https://github.com/nodejs/node/pull/31352
Fixes: https://github.com/nodejs/node/issues/29786
Refs: https://github.com/nodejs/node/pull/29792
Refs: https://github.com/nodejs/node/issues/24491
Reviewed-By: Anna Henningsen <anna@addaleax.net>
Reviewed-By: Rich Trott <rtrott@gmail.com>
Diffstat (limited to 'doc')
-rw-r--r-- | doc/api/buffer.md | 15 |
1 files changed, 14 insertions, 1 deletions
diff --git a/doc/api/buffer.md b/doc/api/buffer.md index c94f03fa06..f033f8a20a 100644 --- a/doc/api/buffer.md +++ b/doc/api/buffer.md @@ -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 |