@@ -313,32 +313,6 @@ Example:
313
313
const buf = new Buffer ([0x62 , 0x75 , 0x66 , 0x66 , 0x65 , 0x72 ]);
314
314
```
315
315
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
-
342
316
### new Buffer(arrayBuffer[ , byteOffset [ , length]] )
343
317
<!-- YAML
344
318
deprecated: v6.0.0
@@ -383,6 +357,32 @@ arr[1] = 6000;
383
357
console .log (buf);
384
358
```
385
359
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
+
386
386
### new Buffer(size)
387
387
<!-- YAML
388
388
deprecated: v6.0.0
@@ -1113,6 +1113,47 @@ Example: Fill a `Buffer` with a two-byte character
1113
1113
console .log (Buffer .allocUnsafe (3 ).fill (' \u0222 ' ));
1114
1114
```
1115
1115
1116
+ ### buf.includes(value[ , byteOffset] [ , encoding ] )
1117
+ <!-- YAML
1118
+ added: v5.3.0
1119
+ -->
1120
+
1121
+ * ` value ` {String | Buffer | Integer} What to search for
1122
+ * ` byteOffset ` {Integer} Where to begin searching in ` buf ` . ** Default:** ` 0 `
1123
+ * ` encoding ` {String} If ` value ` is a string, this is its encoding.
1124
+ ** Default:** ` 'utf8' `
1125
+ * Returns: {Boolean} ` true ` if ` value ` was found in ` buf ` , ` false ` otherwise
1126
+
1127
+ Equivalent to [ ` buf.indexOf() !== -1 ` ] [ `buf.indexOf()` ] .
1128
+
1129
+ Examples:
1130
+
1131
+ ``` js
1132
+ const buf = Buffer .from (' this is a buffer' );
1133
+
1134
+ // Prints: true
1135
+ console .log (buf .includes (' this' ));
1136
+
1137
+ // Prints: true
1138
+ console .log (buf .includes (' is' ));
1139
+
1140
+ // Prints: true
1141
+ console .log (buf .includes (Buffer .from (' a buffer' )));
1142
+
1143
+ // Prints: true
1144
+ // (97 is the decimal ASCII value for 'a')
1145
+ console .log (buf .includes (97 ));
1146
+
1147
+ // Prints: false
1148
+ console .log (buf .includes (Buffer .from (' a buffer example' )));
1149
+
1150
+ // Prints: true
1151
+ console .log (buf .includes (Buffer .from (' a buffer example' ).slice (0 , 8 )));
1152
+
1153
+ // Prints: false
1154
+ console .log (buf .includes (' this' , 4 ));
1155
+ ```
1156
+
1116
1157
### buf.indexOf(value[ , byteOffset] [ , encoding ] )
1117
1158
<!-- YAML
1118
1159
added: v1.5.0
@@ -1192,47 +1233,6 @@ console.log(b.indexOf('b', null));
1192
1233
console .log (b .indexOf (' b' , []));
1193
1234
```
1194
1235
1195
- ### buf.includes(value[ , byteOffset] [ , encoding ] )
1196
- <!-- YAML
1197
- added: v5.3.0
1198
- -->
1199
-
1200
- * ` value ` {String | Buffer | Integer} What to search for
1201
- * ` byteOffset ` {Integer} Where to begin searching in ` buf ` . ** Default:** ` 0 `
1202
- * ` encoding ` {String} If ` value ` is a string, this is its encoding.
1203
- ** Default:** ` 'utf8' `
1204
- * Returns: {Boolean} ` true ` if ` value ` was found in ` buf ` , ` false ` otherwise
1205
-
1206
- Equivalent to [ ` buf.indexOf() !== -1 ` ] [ `buf.indexOf()` ] .
1207
-
1208
- Examples:
1209
-
1210
- ``` js
1211
- const buf = Buffer .from (' this is a buffer' );
1212
-
1213
- // Prints: true
1214
- console .log (buf .includes (' this' ));
1215
-
1216
- // Prints: true
1217
- console .log (buf .includes (' is' ));
1218
-
1219
- // Prints: true
1220
- console .log (buf .includes (Buffer .from (' a buffer' )));
1221
-
1222
- // Prints: true
1223
- // (97 is the decimal ASCII value for 'a')
1224
- console .log (buf .includes (97 ));
1225
-
1226
- // Prints: false
1227
- console .log (buf .includes (Buffer .from (' a buffer example' )));
1228
-
1229
- // Prints: true
1230
- console .log (buf .includes (Buffer .from (' a buffer example' ).slice (0 , 8 )));
1231
-
1232
- // Prints: false
1233
- console .log (buf .includes (' this' , 4 ));
1234
- ```
1235
-
1236
1236
### buf.keys()
1237
1237
<!-- YAML
1238
1238
added: v1.1.0
@@ -1878,6 +1878,35 @@ buf2.swap64();
1878
1878
Note that JavaScript cannot encode 64-bit integers. This method is intended
1879
1879
for working with 64-bit floats.
1880
1880
1881
+ ### buf.toJSON()
1882
+ <!-- YAML
1883
+ added: v0.9.2
1884
+ -->
1885
+
1886
+ * Returns: {Object}
1887
+
1888
+ Returns a JSON representation of ` buf ` . [ ` JSON.stringify() ` ] implicitly calls
1889
+ this function when stringifying a ` Buffer ` instance.
1890
+
1891
+ Example:
1892
+
1893
+ ``` js
1894
+ const buf = Buffer .from ([0x1 , 0x2 , 0x3 , 0x4 , 0x5 ]);
1895
+ const json = JSON .stringify (buf);
1896
+
1897
+ // Prints: {"type":"Buffer","data":[1,2,3,4,5]}
1898
+ console .log (json);
1899
+
1900
+ const copy = JSON .parse (json, (key , value ) => {
1901
+ return value && value .type === ' Buffer'
1902
+ ? Buffer .from (value .data )
1903
+ : value;
1904
+ });
1905
+
1906
+ // Prints: <Buffer 01 02 03 04 05>
1907
+ console .log (copy);
1908
+ ```
1909
+
1881
1910
### buf.toString([ encoding[ , start[ , end]]] )
1882
1911
<!-- YAML
1883
1912
added: v0.1.90
@@ -1921,35 +1950,6 @@ console.log(buf2.toString('utf8', 0, 3));
1921
1950
console .log (buf2 .toString (undefined , 0 , 3 ));
1922
1951
```
1923
1952
1924
- ### buf.toJSON()
1925
- <!-- YAML
1926
- added: v0.9.2
1927
- -->
1928
-
1929
- * Returns: {Object}
1930
-
1931
- Returns a JSON representation of ` buf ` . [ ` JSON.stringify() ` ] implicitly calls
1932
- this function when stringifying a ` Buffer ` instance.
1933
-
1934
- Example:
1935
-
1936
- ``` js
1937
- const buf = Buffer .from ([0x1 , 0x2 , 0x3 , 0x4 , 0x5 ]);
1938
- const json = JSON .stringify (buf);
1939
-
1940
- // Prints: {"type":"Buffer","data":[1,2,3,4,5]}
1941
- console .log (json);
1942
-
1943
- const copy = JSON .parse (json, (key , value ) => {
1944
- return value && value .type === ' Buffer'
1945
- ? Buffer .from (value .data )
1946
- : value;
1947
- });
1948
-
1949
- // Prints: <Buffer 01 02 03 04 05>
1950
- console .log (copy);
1951
- ```
1952
-
1953
1953
### buf.values()
1954
1954
<!-- YAML
1955
1955
added: v1.1.0
0 commit comments