@@ -313,32 +313,6 @@ Example:
313313const buf = new Buffer ([0x62 , 0x75 , 0x66 , 0x66 , 0x65 , 0x72 ]);
314314```
315315
316- ### new Buffer(buffer)
317- <!-- YAML
318- deprecated: v6.0.0
319- -->
320-
321- > Stability: 0 - Deprecated: Use [ ` Buffer.from(buffer) ` ] instead.
322-
323- * ` buffer ` {Buffer} An existing ` Buffer ` to copy data from
324-
325- Copies the passed ` buffer ` data onto a new ` Buffer ` instance.
326-
327- Example:
328-
329- ``` js
330- const buf1 = new Buffer (' buffer' );
331- const buf2 = new Buffer (buf1);
332-
333- buf1[0 ] = 0x61 ;
334-
335- // Prints: auffer
336- console .log (buf1 .toString ());
337-
338- // Prints: buffer
339- console .log (buf2 .toString ());
340- ```
341-
342316### new Buffer(arrayBuffer[ , byteOffset [ , length]] )
343317<!-- YAML
344318deprecated: v6.0.0
@@ -383,6 +357,32 @@ arr[1] = 6000;
383357console .log (buf);
384358```
385359
360+ ### new Buffer(buffer)
361+ <!-- YAML
362+ deprecated: v6.0.0
363+ -->
364+
365+ > Stability: 0 - Deprecated: Use [ ` Buffer.from(buffer) ` ] instead.
366+
367+ * ` buffer ` {Buffer} An existing ` Buffer ` to copy data from
368+
369+ Copies the passed ` buffer ` data onto a new ` Buffer ` instance.
370+
371+ Example:
372+
373+ ``` js
374+ const buf1 = new Buffer (' buffer' );
375+ const buf2 = new Buffer (buf1);
376+
377+ buf1[0 ] = 0x61 ;
378+
379+ // Prints: auffer
380+ console .log (buf1 .toString ());
381+
382+ // Prints: buffer
383+ console .log (buf2 .toString ());
384+ ```
385+
386386### new Buffer(size)
387387<!-- YAML
388388deprecated: v6.0.0
@@ -1100,6 +1100,47 @@ Example: Fill a `Buffer` with a two-byte character
11001100console .log (Buffer .allocUnsafe (3 ).fill (' \u0222 ' ));
11011101```
11021102
1103+ ### buf.includes(value[ , byteOffset] [ , encoding ] )
1104+ <!-- YAML
1105+ added: v5.3.0
1106+ -->
1107+
1108+ * ` value ` {String | Buffer | Integer} What to search for
1109+ * ` byteOffset ` {Integer} Where to begin searching in ` buf ` . ** Default:** ` 0 `
1110+ * ` encoding ` {String} If ` value ` is a string, this is its encoding.
1111+ ** Default:** ` 'utf8' `
1112+ * Returns: {Boolean} ` true ` if ` value ` was found in ` buf ` , ` false ` otherwise
1113+
1114+ Equivalent to [ ` buf.indexOf() !== -1 ` ] [ `buf.indexOf()` ] .
1115+
1116+ Examples:
1117+
1118+ ``` js
1119+ const buf = Buffer .from (' this is a buffer' );
1120+
1121+ // Prints: true
1122+ console .log (buf .includes (' this' ));
1123+
1124+ // Prints: true
1125+ console .log (buf .includes (' is' ));
1126+
1127+ // Prints: true
1128+ console .log (buf .includes (Buffer .from (' a buffer' )));
1129+
1130+ // Prints: true
1131+ // (97 is the decimal ASCII value for 'a')
1132+ console .log (buf .includes (97 ));
1133+
1134+ // Prints: false
1135+ console .log (buf .includes (Buffer .from (' a buffer example' )));
1136+
1137+ // Prints: true
1138+ console .log (buf .includes (Buffer .from (' a buffer example' ).slice (0 , 8 )));
1139+
1140+ // Prints: false
1141+ console .log (buf .includes (' this' , 4 ));
1142+ ```
1143+
11031144### buf.indexOf(value[ , byteOffset] [ , encoding ] )
11041145<!-- YAML
11051146added: v1.5.0
@@ -1179,47 +1220,6 @@ console.log(b.indexOf('b', null));
11791220console .log (b .indexOf (' b' , []));
11801221```
11811222
1182- ### buf.includes(value[ , byteOffset] [ , encoding ] )
1183- <!-- YAML
1184- added: v5.3.0
1185- -->
1186-
1187- * ` value ` {String | Buffer | Integer} What to search for
1188- * ` byteOffset ` {Integer} Where to begin searching in ` buf ` . ** Default:** ` 0 `
1189- * ` encoding ` {String} If ` value ` is a string, this is its encoding.
1190- ** Default:** ` 'utf8' `
1191- * Returns: {Boolean} ` true ` if ` value ` was found in ` buf ` , ` false ` otherwise
1192-
1193- Equivalent to [ ` buf.indexOf() !== -1 ` ] [ `buf.indexOf()` ] .
1194-
1195- Examples:
1196-
1197- ``` js
1198- const buf = Buffer .from (' this is a buffer' );
1199-
1200- // Prints: true
1201- console .log (buf .includes (' this' ));
1202-
1203- // Prints: true
1204- console .log (buf .includes (' is' ));
1205-
1206- // Prints: true
1207- console .log (buf .includes (Buffer .from (' a buffer' )));
1208-
1209- // Prints: true
1210- // (97 is the decimal ASCII value for 'a')
1211- console .log (buf .includes (97 ));
1212-
1213- // Prints: false
1214- console .log (buf .includes (Buffer .from (' a buffer example' )));
1215-
1216- // Prints: true
1217- console .log (buf .includes (Buffer .from (' a buffer example' ).slice (0 , 8 )));
1218-
1219- // Prints: false
1220- console .log (buf .includes (' this' , 4 ));
1221- ```
1222-
12231223### buf.keys()
12241224<!-- YAML
12251225added: v1.1.0
@@ -1859,6 +1859,35 @@ buf2.swap64();
18591859Note that JavaScript cannot encode 64-bit integers. This method is intended
18601860for working with 64-bit floats.
18611861
1862+ ### buf.toJSON()
1863+ <!-- YAML
1864+ added: v0.9.2
1865+ -->
1866+
1867+ * Returns: {Object}
1868+
1869+ Returns a JSON representation of ` buf ` . [ ` JSON.stringify() ` ] implicitly calls
1870+ this function when stringifying a ` Buffer ` instance.
1871+
1872+ Example:
1873+
1874+ ``` js
1875+ const buf = Buffer .from ([0x1 , 0x2 , 0x3 , 0x4 , 0x5 ]);
1876+ const json = JSON .stringify (buf);
1877+
1878+ // Prints: {"type":"Buffer","data":[1,2,3,4,5]}
1879+ console .log (json);
1880+
1881+ const copy = JSON .parse (json, (key , value ) => {
1882+ return value && value .type === ' Buffer'
1883+ ? Buffer .from (value .data )
1884+ : value;
1885+ });
1886+
1887+ // Prints: <Buffer 01 02 03 04 05>
1888+ console .log (copy);
1889+ ```
1890+
18621891### buf.toString([ encoding[ , start[ , end]]] )
18631892<!-- YAML
18641893added: v0.1.90
@@ -1902,35 +1931,6 @@ console.log(buf2.toString('utf8', 0, 3));
19021931console .log (buf2 .toString (undefined , 0 , 3 ));
19031932```
19041933
1905- ### buf.toJSON()
1906- <!-- YAML
1907- added: v0.9.2
1908- -->
1909-
1910- * Returns: {Object}
1911-
1912- Returns a JSON representation of ` buf ` . [ ` JSON.stringify() ` ] implicitly calls
1913- this function when stringifying a ` Buffer ` instance.
1914-
1915- Example:
1916-
1917- ``` js
1918- const buf = Buffer .from ([0x1 , 0x2 , 0x3 , 0x4 , 0x5 ]);
1919- const json = JSON .stringify (buf);
1920-
1921- // Prints: {"type":"Buffer","data":[1,2,3,4,5]}
1922- console .log (json);
1923-
1924- const copy = JSON .parse (json, (key , value ) => {
1925- return value && value .type === ' Buffer'
1926- ? Buffer .from (value .data )
1927- : value;
1928- });
1929-
1930- // Prints: <Buffer 01 02 03 04 05>
1931- console .log (copy);
1932- ```
1933-
19341934### buf.values()
19351935<!-- YAML
19361936added: v1.1.0
0 commit comments