From 305633e9b4bf0287dacaba4c030c0e2b64837ec1 Mon Sep 17 00:00:00 2001 From: Rich Trott Date: Tue, 27 Mar 2018 21:34:43 -0700 Subject: [PATCH 1/2] 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. --- doc/api/buffer.md | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/doc/api/buffer.md b/doc/api/buffer.md index b551f72ad98029..0b8e7c6b976725 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. +A character encoding may be specified when converting between a string and a +`Buffer`. ```js const buf = Buffer.from('hello world', 'ascii'); From 6e7cbe37f975ae4cb05883676870cb6d025bc46b Mon Sep 17 00:00:00 2001 From: Rich Trott Date: Wed, 28 Mar 2018 21:42:29 -0700 Subject: [PATCH 2/2] squash: address requests for changes --- doc/api/buffer.md | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/doc/api/buffer.md b/doc/api/buffer.md index 0b8e7c6b976725..99c9c79d71d74d 100644 --- a/doc/api/buffer.md +++ b/doc/api/buffer.md @@ -149,8 +149,8 @@ changes: description: Removed the deprecated `raw` and `raws` encodings. --> -A character encoding may be specified when converting between a string and a -`Buffer`. +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'); @@ -159,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: