summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJackson Tian <shyvo1987@gmail.com>2016-04-25 10:36:57 +0800
committerJackson Tian <shyvo1987@gmail.com>2016-04-27 13:23:41 +0800
commite556dd3856d42ae8e94e27846b8cf7c1dfff05d3 (patch)
tree43801cfa990096ed1e9ad5451d76ca231647b67f
parentcee4c25c9281d106f80b20ba7854bf9003f9357a (diff)
downloadandroid-node-v8-e556dd3856d42ae8e94e27846b8cf7c1dfff05d3.tar.gz
android-node-v8-e556dd3856d42ae8e94e27846b8cf7c1dfff05d3.tar.bz2
android-node-v8-e556dd3856d42ae8e94e27846b8cf7c1dfff05d3.zip
doc: use Buffer.from() instead of new Buffer()
Use new API of Buffer to developers in most documents. PR-URL: https://github.com/nodejs/node/pull/6367 Reviewed-By: Colin Ihrig <cjihrig@gmail.com> Reviewed-By: James M Snell <jasnell@gmail.com> Reviewed-By: Сковорода Никита Андреевич <chalkerx@gmail.com>
-rw-r--r--doc/api/crypto.md2
-rw-r--r--doc/api/dgram.md6
-rw-r--r--doc/api/stream.md4
-rw-r--r--doc/api/string_decoder.md4
-rw-r--r--doc/api/util.md2
-rw-r--r--doc/api/zlib.md4
-rw-r--r--lib/string_decoder.js4
7 files changed, 13 insertions, 13 deletions
diff --git a/doc/api/crypto.md b/doc/api/crypto.md
index 14adffd8d8..e84c10dfa4 100644
--- a/doc/api/crypto.md
+++ b/doc/api/crypto.md
@@ -93,7 +93,7 @@ The `spkac` argument must be a Node.js [`Buffer`][].
```js
const cert = require('crypto').Certificate();
const spkac = getSpkacSomehow();
-console.log(cert.verifySpkac(new Buffer(spkac)));
+console.log(cert.verifySpkac(Buffer.from(spkac)));
// Prints true or false
```
diff --git a/doc/api/dgram.md b/doc/api/dgram.md
index 1bb5155578..53eeb81898 100644
--- a/doc/api/dgram.md
+++ b/doc/api/dgram.md
@@ -233,7 +233,7 @@ Example of sending a UDP packet to a random port on `localhost`;
```js
const dgram = require('dgram');
-const message = new Buffer('Some bytes');
+const message = Buffer.from('Some bytes');
const client = dgram.createSocket('udp4');
client.send(message, 41234, 'localhost', (err) => {
client.close();
@@ -244,8 +244,8 @@ Example of sending a UDP packet composed of multiple buffers to a random port on
```js
const dgram = require('dgram');
-const buf1 = new Buffer('Some ');
-const buf2 = new Buffer('bytes');
+const buf1 = Buffer.from('Some ');
+const buf2 = Buffer.from('bytes');
const client = dgram.createSocket('udp4');
client.send([buf1, buf2], 41234, 'localhost', (err) => {
client.close();
diff --git a/doc/api/stream.md b/doc/api/stream.md
index d2d0c4487e..83fb13d71e 100644
--- a/doc/api/stream.md
+++ b/doc/api/stream.md
@@ -490,7 +490,7 @@ function parseHeader(stream, callback) {
var split = str.split(/\n\n/);
header += split.shift();
var remaining = split.join('\n\n');
- var buf = new Buffer(remaining, 'utf8');
+ var buf = Buffer.from(remaining, 'utf8');
if (buf.length)
stream.unshift(buf);
stream.removeListener('error', callback);
@@ -985,7 +985,7 @@ Counter.prototype._read = function() {
this.push(null);
else {
var str = '' + i;
- var buf = new Buffer(str, 'ascii');
+ var buf = Buffer.from(str, 'ascii');
this.push(buf);
}
};
diff --git a/doc/api/string_decoder.md b/doc/api/string_decoder.md
index d1de27dc4a..f979e7dd37 100644
--- a/doc/api/string_decoder.md
+++ b/doc/api/string_decoder.md
@@ -10,10 +10,10 @@ additional support for utf8.
const StringDecoder = require('string_decoder').StringDecoder;
const decoder = new StringDecoder('utf8');
-const cent = new Buffer([0xC2, 0xA2]);
+const cent = Buffer.from([0xC2, 0xA2]);
console.log(decoder.write(cent));
-const euro = new Buffer([0xE2, 0x82, 0xAC]);
+const euro = Buffer.from([0xE2, 0x82, 0xAC]);
console.log(decoder.write(euro));
```
diff --git a/doc/api/util.md b/doc/api/util.md
index 692c9b2e45..d298ae4b44 100644
--- a/doc/api/util.md
+++ b/doc/api/util.md
@@ -297,7 +297,7 @@ util.isBuffer({ length: 0 })
// false
util.isBuffer([])
// false
-util.isBuffer(new Buffer('hello world'))
+util.isBuffer(Buffer.from('hello world'))
// true
```
diff --git a/doc/api/zlib.md b/doc/api/zlib.md
index fa3f8ee215..8cd455eaee 100644
--- a/doc/api/zlib.md
+++ b/doc/api/zlib.md
@@ -37,7 +37,7 @@ zlib.deflate(input, (err, buffer) => {
}
});
-const buffer = new Buffer('eJzT0yMAAGTvBe8=', 'base64');
+const buffer = Buffer.from('eJzT0yMAAGTvBe8=', 'base64');
zlib.unzip(buffer, (err, buffer) => {
if (!err) {
console.log(buffer.toString());
@@ -117,7 +117,7 @@ method that is used to compressed the last chunk of input data:
```js
// This is a truncated version of the buffer from the above examples
-const buffer = new Buffer('eJzT0yMA', 'base64');
+const buffer = Buffer.from('eJzT0yMA', 'base64');
zlib.unzip(buffer, { finishFlush: zlib.Z_SYNC_FLUSH }, (err, buffer) => {
if (!err) {
diff --git a/lib/string_decoder.js b/lib/string_decoder.js
index 1680392157..4047489e6c 100644
--- a/lib/string_decoder.js
+++ b/lib/string_decoder.js
@@ -58,8 +58,8 @@ const StringDecoder = exports.StringDecoder = function(encoding) {
// returned when calling write again with the remaining bytes.
//
// Note: Converting a Buffer containing an orphan surrogate to a String
-// currently works, but converting a String to a Buffer (via `new Buffer`, or
-// Buffer#write) will replace incomplete surrogates with the unicode
+// currently works, but converting a String to a Buffer (via `Buffer.from()`,
+// or Buffer#write) will replace incomplete surrogates with the unicode
// replacement character. See https://codereview.chromium.org/121173009/ .
StringDecoder.prototype.write = function(buffer) {
var charStr = '';