| FazBrowse GitHub Viewer | Trending | | Home |
| Tools: [Download Repo ZIP] [Original HTTPS Page] |
1 parent cbbe95e commit 19fb134
7 files changed
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -93,7 +93,7 @@ The `spkac` argument must be a Node.js [`Buffer`][]. | |||
| 93 | 93 | ```js | |
| 94 | 94 | const cert = require('crypto').Certificate(); | |
| 95 | 95 | const spkac = getSpkacSomehow(); | |
| 96 | - console.log(cert.verifySpkac(new Buffer(spkac))); | ||
| 96 | + console.log(cert.verifySpkac(Buffer.from(spkac))); | ||
| 97 | 97 | // Prints true or false | |
| 98 | 98 | ``` | |
| 99 | 99 | ||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -233,7 +233,7 @@ Example of sending a UDP packet to a random port on `localhost`; | |||
| 233 | 233 | ||
| 234 | 234 | ```js | |
| 235 | 235 | const dgram = require('dgram'); | |
| 236 | - const message = new Buffer('Some bytes'); | ||
| 236 | + const message = Buffer.from('Some bytes'); | ||
| 237 | 237 | const client = dgram.createSocket('udp4'); | |
| 238 | 238 | client.send(message, 41234, 'localhost', (err) => { | |
| 239 | 239 | client.close(); | |
@@ -244,8 +244,8 @@ Example of sending a UDP packet composed of multiple buffers to a random port on | |||
| 244 | 244 | ||
| 245 | 245 | ```js | |
| 246 | 246 | const dgram = require('dgram'); | |
| 247 | - const buf1 = new Buffer('Some '); | ||
| 248 | - const buf2 = new Buffer('bytes'); | ||
| 247 | + const buf1 = Buffer.from('Some '); | ||
| 248 | + const buf2 = Buffer.from('bytes'); | ||
| 249 | 249 | const client = dgram.createSocket('udp4'); | |
| 250 | 250 | client.send([buf1, buf2], 41234, 'localhost', (err) => { | |
| 251 | 251 | client.close(); | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -490,7 +490,7 @@ function parseHeader(stream, callback) { | |||
| 490 | 490 | var split = str.split(/\n\n/); | |
| 491 | 491 | header += split.shift(); | |
| 492 | 492 | var remaining = split.join('\n\n'); | |
| 493 | - var buf = new Buffer(remaining, 'utf8'); | ||
| 493 | + var buf = Buffer.from(remaining, 'utf8'); | ||
| 494 | 494 | if (buf.length) | |
| 495 | 495 | stream.unshift(buf); | |
| 496 | 496 | stream.removeListener('error', callback); | |
@@ -985,7 +985,7 @@ Counter.prototype._read = function() { | |||
| 985 | 985 | this.push(null); | |
| 986 | 986 | else { | |
| 987 | 987 | var str = '' + i; | |
| 988 | - var buf = new Buffer(str, 'ascii'); | ||
| 988 | + var buf = Buffer.from(str, 'ascii'); | ||
| 989 | 989 | this.push(buf); | |
| 990 | 990 | } | |
| 991 | 991 | }; | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -10,10 +10,10 @@ additional support for utf8. | |||
| 10 | 10 | const StringDecoder = require('string_decoder').StringDecoder; | |
| 11 | 11 | const decoder = new StringDecoder('utf8'); | |
| 12 | 12 | ||
| 13 | - const cent = new Buffer([0xC2, 0xA2]); | ||
| 13 | + const cent = Buffer.from([0xC2, 0xA2]); | ||
| 14 | 14 | console.log(decoder.write(cent)); | |
| 15 | 15 | ||
| 16 | - const euro = new Buffer([0xE2, 0x82, 0xAC]); | ||
| 16 | + const euro = Buffer.from([0xE2, 0x82, 0xAC]); | ||
| 17 | 17 | console.log(decoder.write(euro)); | |
| 18 | 18 | ``` | |
| 19 | 19 | ||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -297,7 +297,7 @@ util.isBuffer({ length: 0 }) | |||
| 297 | 297 | // false | |
| 298 | 298 | util.isBuffer([]) | |
| 299 | 299 | // false | |
| 300 | - util.isBuffer(new Buffer('hello world')) | ||
| 300 | + util.isBuffer(Buffer.from('hello world')) | ||
| 301 | 301 | // true | |
| 302 | 302 | ``` | |
| 303 | 303 | ||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -37,7 +37,7 @@ zlib.deflate(input, (err, buffer) => { | |||
| 37 | 37 | } | |
| 38 | 38 | }); | |
| 39 | 39 | ||
| 40 | - const buffer = new Buffer('eJzT0yMAAGTvBe8=', 'base64'); | ||
| 40 | + const buffer = Buffer.from('eJzT0yMAAGTvBe8=', 'base64'); | ||
| 41 | 41 | zlib.unzip(buffer, (err, buffer) => { | |
| 42 | 42 | if (!err) { | |
| 43 | 43 | console.log(buffer.toString()); | |
@@ -117,7 +117,7 @@ method that is used to compressed the last chunk of input data: | |||
| 117 | 117 | ||
| 118 | 118 | ```js | |
| 119 | 119 | // This is a truncated version of the buffer from the above examples | |
| 120 | - const buffer = new Buffer('eJzT0yMA', 'base64'); | ||
| 120 | + const buffer = Buffer.from('eJzT0yMA', 'base64'); | ||
| 121 | 121 | ||
| 122 | 122 | zlib.unzip(buffer, { finishFlush: zlib.Z_SYNC_FLUSH }, (err, buffer) => { | |
| 123 | 123 | if (!err) { | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -58,8 +58,8 @@ const StringDecoder = exports.StringDecoder = function(encoding) { | |||
| 58 | 58 | // returned when calling write again with the remaining bytes. | |
| 59 | 59 | // | |
| 60 | 60 | // Note: Converting a Buffer containing an orphan surrogate to a String | |
| 61 | - // currently works, but converting a String to a Buffer (via `new Buffer`, or | ||
| 62 | - // Buffer#write) will replace incomplete surrogates with the unicode | ||
| 61 | + // currently works, but converting a String to a Buffer (via `Buffer.from()`, | ||
| 62 | + // or Buffer#write) will replace incomplete surrogates with the unicode | ||
| 63 | 63 | // replacement character. See https://codereview.chromium.org/121173009/ . | |
| 64 | 64 | StringDecoder.prototype.write = function(buffer) { | |
| 65 | 65 | var charStr = ''; | |
| Back | FazBrowse Home | New Git URL |
0 commit comments