From 9f20534889343b0cdf0d477a75ace6921d33e71a Mon Sep 17 00:00:00 2001 From: Rich Trott Date: Tue, 27 Mar 2018 21:34:43 -0700 Subject: [PATCH] doc: shorten character encoding introduction Keep the introduction for Buffers and character encodings short and to the point. The current introduction doesn't provide much in the way of useful additional information, but it is a bit confusing in its wording. ("such as" seems like it ought to refer to "encoded characters" but it actually refers to character encodings, which are not mentioned in the sentence. It may be arguable as to whether "hex-encoded" is in fact a character encoding, whether it should be stylized as "Hex-encoded" or not, and whether it should be spelled out as "Hexadecimal-encoded". None of that information is particularly useful to the end user at this point in the text. Omitting it simplifies and improves the documentation.) Additionally, the section is now wrapped to 80 characters. PR-URL: https://github.com/nodejs/node/pull/19648 Reviewed-By: James M Snell Reviewed-By: Gireesh Punathil Reviewed-By: Tiancheng "Timothy" Gu --- doc/api/buffer.md | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) diff --git a/doc/api/buffer.md b/doc/api/buffer.md index 56476d301f24eb..f080320089ee81 100644 --- a/doc/api/buffer.md +++ b/doc/api/buffer.md @@ -149,10 +149,8 @@ changes: description: Removed the deprecated `raw` and `raws` encodings. --> -`Buffer` instances are commonly used to represent sequences of encoded characters -such as UTF-8, UCS2, Base64, or even Hex-encoded data. It is possible to -convert back and forth between `Buffer` instances and ordinary JavaScript strings -by using an explicit character encoding. +When string data is stored in or extracted out of a `Buffer` instance, a +character encoding may be specified. ```js const buf = Buffer.from('hello world', 'ascii'); @@ -161,6 +159,11 @@ console.log(buf.toString('hex')); // Prints: 68656c6c6f20776f726c64 console.log(buf.toString('base64')); // Prints: aGVsbG8gd29ybGQ= + +console.log(Buffer.from('fhqwhgads', 'ascii')); +// Prints: +console.log(Buffer.from('fhqwhgads', 'ucs2')); +// Prints: ``` The character encodings currently supported by Node.js include: