@@ -424,8 +424,8 @@ deprecated: v6.0.0
424
424
> Stability: 0 - Deprecated:
425
425
> Use [ ` Buffer.from(string[, encoding]) ` ] [ `Buffer.from(string)` ] instead.
426
426
427
- * ` string ` {String } String to encode
428
- * ` encoding ` {String } The encoding of ` string ` . ** Default:** ` 'utf8' `
427
+ * ` string ` {string } String to encode
428
+ * ` encoding ` {string } The encoding of ` string ` . ** Default:** ` 'utf8' `
429
429
430
430
Creates a new ` Buffer ` containing the given JavaScript string ` string ` . If
431
431
provided, the ` encoding ` parameter identifies the character encoding of ` string ` .
@@ -454,9 +454,9 @@ added: v5.10.0
454
454
-->
455
455
456
456
* ` size ` {Integer} The desired length of the new ` Buffer `
457
- * ` fill ` {String | Buffer | Integer} A value to pre-fill the new ` Buffer ` with.
457
+ * ` fill ` {string | Buffer | Integer} A value to pre-fill the new ` Buffer ` with.
458
458
** Default:** ` 0 `
459
- * ` encoding ` {String } If ` fill ` is a string, this is its encoding.
459
+ * ` encoding ` {string } If ` fill ` is a string, this is its encoding.
460
460
** Default:** ` 'utf8' `
461
461
462
462
Allocates a new ` Buffer ` of ` size ` bytes. If ` fill ` is ` undefined ` , the
@@ -609,9 +609,9 @@ A `TypeError` will be thrown if `size` is not a number.
609
609
added: v0.1.90
610
610
-->
611
611
612
- * ` string ` {String | Buffer | TypedArray | DataView | ArrayBuffer} A value to
612
+ * ` string ` {string | Buffer | TypedArray | DataView | ArrayBuffer} A value to
613
613
calculate the length of
614
- * ` encoding ` {String } If ` string ` is a string, this is its encoding.
614
+ * ` encoding ` {string } If ` string ` is a string, this is its encoding.
615
615
** Default:** ` 'utf8' `
616
616
* Returns: {Integer} The number of bytes contained within ` string `
617
617
@@ -805,8 +805,8 @@ A `TypeError` will be thrown if `buffer` is not a `Buffer`.
805
805
added: v5.10.0
806
806
-->
807
807
808
- * ` string ` {String } A string to encode.
809
- * ` encoding ` {String } The encoding of ` string ` . ** Default:** ` 'utf8' `
808
+ * ` string ` {string } A string to encode.
809
+ * ` encoding ` {string } The encoding of ` string ` . ** Default:** ` 'utf8' `
810
810
811
811
Creates a new ` Buffer ` containing the given JavaScript string ` string ` . If
812
812
provided, the ` encoding ` parameter identifies the character encoding of ` string ` .
@@ -846,7 +846,7 @@ Returns `true` if `obj` is a `Buffer`, `false` otherwise.
846
846
added: v0.9.1
847
847
-->
848
848
849
- * ` encoding ` {String } A character encoding name to check
849
+ * ` encoding ` {string } A character encoding name to check
850
850
* Returns: {Boolean}
851
851
852
852
Returns ` true ` if ` encoding ` contains a supported character encoding, or ` false `
@@ -1075,10 +1075,10 @@ console.log(buf1.equals(buf3));
1075
1075
added: v0.5.0
1076
1076
-->
1077
1077
1078
- * ` value ` {String | Buffer | Integer} The value to fill ` buf ` with
1078
+ * ` value ` {string | Buffer | Integer} The value to fill ` buf ` with
1079
1079
* ` offset ` {Integer} Where to start filling ` buf ` . ** Default:** ` 0 `
1080
1080
* ` end ` {Integer} Where to stop filling ` buf ` (not inclusive). ** Default:** [ ` buf.length ` ]
1081
- * ` encoding ` {String } If ` value ` is a string, this is its encoding.
1081
+ * ` encoding ` {string } If ` value ` is a string, this is its encoding.
1082
1082
** Default:** ` 'utf8' `
1083
1083
* Returns: {Buffer} A reference to ` buf `
1084
1084
@@ -1107,14 +1107,55 @@ Example: Fill a `Buffer` with a two-byte character
1107
1107
console .log (Buffer .allocUnsafe (3 ).fill (' \u0222 ' ));
1108
1108
```
1109
1109
1110
+ ### buf.includes(value[ , byteOffset] [ , encoding ] )
1111
+ <!-- YAML
1112
+ added: v5.3.0
1113
+ -->
1114
+
1115
+ * ` value ` {string | Buffer | Integer} What to search for
1116
+ * ` byteOffset ` {Integer} Where to begin searching in ` buf ` . ** Default:** ` 0 `
1117
+ * ` encoding ` {string} If ` value ` is a string, this is its encoding.
1118
+ ** Default:** ` 'utf8' `
1119
+ * Returns: {Boolean} ` true ` if ` value ` was found in ` buf ` , ` false ` otherwise
1120
+
1121
+ Equivalent to [ ` buf.indexOf() !== -1 ` ] [ `buf.indexOf()` ] .
1122
+
1123
+ Examples:
1124
+
1125
+ ``` js
1126
+ const buf = Buffer .from (' this is a buffer' );
1127
+
1128
+ // Prints: true
1129
+ console .log (buf .includes (' this' ));
1130
+
1131
+ // Prints: true
1132
+ console .log (buf .includes (' is' ));
1133
+
1134
+ // Prints: true
1135
+ console .log (buf .includes (Buffer .from (' a buffer' )));
1136
+
1137
+ // Prints: true
1138
+ // (97 is the decimal ASCII value for 'a')
1139
+ console .log (buf .includes (97 ));
1140
+
1141
+ // Prints: false
1142
+ console .log (buf .includes (Buffer .from (' a buffer example' )));
1143
+
1144
+ // Prints: true
1145
+ console .log (buf .includes (Buffer .from (' a buffer example' ).slice (0 , 8 )));
1146
+
1147
+ // Prints: false
1148
+ console .log (buf .includes (' this' , 4 ));
1149
+ ```
1150
+
1110
1151
### buf.indexOf(value[ , byteOffset] [ , encoding ] )
1111
1152
<!-- YAML
1112
1153
added: v1.5.0
1113
1154
-->
1114
1155
1115
1156
* ` value ` {String | Buffer | Integer} What to search for
1116
1157
* ` byteOffset ` {Integer} Where to begin searching in ` buf ` . ** Default:** ` 0 `
1117
- * ` encoding ` {String } If ` value ` is a string, this is its encoding.
1158
+ * ` encoding ` {string } If ` value ` is a string, this is its encoding.
1118
1159
** Default:** ` 'utf8' `
1119
1160
* Returns: {Integer} The index of the first occurrence of ` value ` in ` buf ` or ` -1 `
1120
1161
if ` buf ` does not contain ` value `
@@ -1261,7 +1302,7 @@ added: v6.0.0
1261
1302
* ` value ` {String | Buffer | Integer} What to search for
1262
1303
* ` byteOffset ` {Integer} Where to begin searching in ` buf ` .
1263
1304
** Default:** [ ` buf.length ` ] ` - 1 `
1264
- * ` encoding ` {String } If ` value ` is a string, this is its encoding.
1305
+ * ` encoding ` {string } If ` value ` is a string, this is its encoding.
1265
1306
** Default:** ` 'utf8' `
1266
1307
* Returns: {Integer} The index of the last occurrence of ` value ` in ` buf ` or ` -1 `
1267
1308
if ` buf ` does not contain ` value `
@@ -1385,7 +1426,7 @@ added: v0.11.15
1385
1426
-->
1386
1427
1387
1428
* ` offset ` {Integer} Where to start reading. Must satisfy: ` 0 <= offset <= buf.length - 8 `
1388
- * ` noAssert ` {Boolean } Skip ` offset ` validation? ** Default:** ` false `
1429
+ * ` noAssert ` {boolean } Skip ` offset ` validation? ** Default:** ` false `
1389
1430
* Returns: {Number}
1390
1431
1391
1432
Reads a 64-bit double from ` buf ` at the specified ` offset ` with specified
@@ -1421,7 +1462,7 @@ added: v0.11.15
1421
1462
-->
1422
1463
1423
1464
* ` offset ` {Integer} Where to start reading. Must satisfy: ` 0 <= offset <= buf.length - 4 `
1424
- * ` noAssert ` {Boolean } Skip ` offset ` validation? ** Default:** ` false `
1465
+ * ` noAssert ` {boolean } Skip ` offset ` validation? ** Default:** ` false `
1425
1466
* Returns: {Number}
1426
1467
1427
1468
Reads a 32-bit float from ` buf ` at the specified ` offset ` with specified
@@ -1456,7 +1497,7 @@ added: v0.5.0
1456
1497
-->
1457
1498
1458
1499
* ` offset ` {Integer} Where to start reading. Must satisfy: ` 0 <= offset <= buf.length - 1 `
1459
- * ` noAssert ` {Boolean } Skip ` offset ` validation? ** Default:** ` false `
1500
+ * ` noAssert ` {boolean } Skip ` offset ` validation? ** Default:** ` false `
1460
1501
* Returns: {Integer}
1461
1502
1462
1503
Reads a signed 8-bit integer from ` buf ` at the specified ` offset ` .
@@ -1488,7 +1529,7 @@ added: v0.5.5
1488
1529
-->
1489
1530
1490
1531
* ` offset ` {Integer} Where to start reading. Must satisfy: ` 0 <= offset <= buf.length - 2 `
1491
- * ` noAssert ` {Boolean } Skip ` offset ` validation? ** Default:** ` false `
1532
+ * ` noAssert ` {boolean } Skip ` offset ` validation? ** Default:** ` false `
1492
1533
* Returns: {Integer}
1493
1534
1494
1535
Reads a signed 16-bit integer from ` buf ` at the specified ` offset ` with
@@ -1522,7 +1563,7 @@ added: v0.5.5
1522
1563
-->
1523
1564
1524
1565
* ` offset ` {Integer} Where to start reading. Must satisfy: ` 0 <= offset <= buf.length - 4 `
1525
- * ` noAssert ` {Boolean } Skip ` offset ` validation? ** Default:** ` false `
1566
+ * ` noAssert ` {boolean } Skip ` offset ` validation? ** Default:** ` false `
1526
1567
* Returns: {Integer}
1527
1568
1528
1569
Reads a signed 32-bit integer from ` buf ` at the specified ` offset ` with
@@ -1557,7 +1598,7 @@ added: v0.11.15
1557
1598
1558
1599
* ` offset ` {Integer} Where to start reading. Must satisfy: ` 0 <= offset <= buf.length - byteLength `
1559
1600
* ` byteLength ` {Integer} How many bytes to read. Must satisfy: ` 0 < byteLength <= 6 `
1560
- * ` noAssert ` {Boolean } Skip ` offset ` and ` byteLength ` validation? ** Default:** ` false `
1601
+ * ` noAssert ` {boolean } Skip ` offset ` and ` byteLength ` validation? ** Default:** ` false `
1561
1602
* Returns: {Integer}
1562
1603
1563
1604
Reads ` byteLength ` number of bytes from ` buf ` at the specified ` offset `
@@ -1588,7 +1629,7 @@ added: v0.5.0
1588
1629
-->
1589
1630
1590
1631
* ` offset ` {Integer} Where to start reading. Must satisfy: ` 0 <= offset <= buf.length - 1 `
1591
- * ` noAssert ` {Boolean } Skip ` offset ` validation? ** Default:** ` false `
1632
+ * ` noAssert ` {boolean } Skip ` offset ` validation? ** Default:** ` false `
1592
1633
* Returns: {Integer}
1593
1634
1594
1635
Reads an unsigned 8-bit integer from ` buf ` at the specified ` offset ` .
@@ -1618,7 +1659,7 @@ added: v0.5.5
1618
1659
-->
1619
1660
1620
1661
* ` offset ` {Integer} Where to start reading. Must satisfy: ` 0 <= offset <= buf.length - 2 `
1621
- * ` noAssert ` {Boolean } Skip ` offset ` validation? ** Default:** ` false `
1662
+ * ` noAssert ` {boolean } Skip ` offset ` validation? ** Default:** ` false `
1622
1663
* Returns: {Integer}
1623
1664
1624
1665
Reads an unsigned 16-bit integer from ` buf ` at the specified ` offset ` with
@@ -1656,7 +1697,7 @@ added: v0.5.5
1656
1697
-->
1657
1698
1658
1699
* ` offset ` {Integer} Where to start reading. Must satisfy: ` 0 <= offset <= buf.length - 4 `
1659
- * ` noAssert ` {Boolean } Skip ` offset ` validation? ** Default:** ` false `
1700
+ * ` noAssert ` {boolean } Skip ` offset ` validation? ** Default:** ` false `
1660
1701
* Returns: {Integer}
1661
1702
1662
1703
Reads an unsigned 32-bit integer from ` buf ` at the specified ` offset ` with
@@ -1689,7 +1730,7 @@ added: v0.11.15
1689
1730
1690
1731
* ` offset ` {Integer} Where to start reading. Must satisfy: ` 0 <= offset <= buf.length - byteLength `
1691
1732
* ` byteLength ` {Integer} How many bytes to read. Must satisfy: ` 0 < byteLength <= 6 `
1692
- * ` noAssert ` {Boolean } Skip ` offset ` and ` byteLength ` validation? ** Default:** ` false `
1733
+ * ` noAssert ` {boolean } Skip ` offset ` and ` byteLength ` validation? ** Default:** ` false `
1693
1734
* Returns: {Integer}
1694
1735
1695
1736
Reads ` byteLength ` number of bytes from ` buf ` at the specified ` offset `
@@ -1871,7 +1912,7 @@ for working with 64-bit floats.
1871
1912
added: v0.1.90
1872
1913
-->
1873
1914
1874
- * ` encoding ` {String } The character encoding to decode to. ** Default:** ` 'utf8' `
1915
+ * ` encoding ` {string } The character encoding to decode to. ** Default:** ` 'utf8' `
1875
1916
* ` start ` {Integer} The byte offset to start decoding at. ** Default:** ` 0 `
1876
1917
* ` end ` {Integer} The byte offset to stop decoding at (not inclusive).
1877
1918
** Default:** [ ` buf.length ` ]
@@ -1981,10 +2022,10 @@ for (const value of buf) {
1981
2022
added: v0.1.90
1982
2023
-->
1983
2024
1984
- * ` string ` {String } String to be written to ` buf `
2025
+ * ` string ` {string } String to be written to ` buf `
1985
2026
* ` offset ` {Integer} Where to start writing ` string ` . ** Default:** ` 0 `
1986
2027
* ` length ` {Integer} How many bytes to write. ** Default:** ` buf.length - offset `
1987
- * ` encoding ` {String } The character encoding of ` string ` . ** Default:** ` 'utf8' `
2028
+ * ` encoding ` {string } The character encoding of ` string ` . ** Default:** ` 'utf8' `
1988
2029
* Returns: {Integer} Number of bytes written
1989
2030
1990
2031
Writes ` string ` to ` buf ` at ` offset ` according to the character encoding in ` encoding ` .
@@ -2009,9 +2050,9 @@ console.log(`${len} bytes: ${buf.toString('utf8', 0, len)}`);
2009
2050
added: v0.11.15
2010
2051
-->
2011
2052
2012
- * ` value ` {Number } Number to be written to ` buf `
2053
+ * ` value ` {number } Number to be written to ` buf `
2013
2054
* ` offset ` {Integer} Where to start writing. Must satisfy: ` 0 <= offset <= buf.length - 8 `
2014
- * ` noAssert ` {Boolean } Skip ` value ` and ` offset ` validation? ** Default:** ` false `
2055
+ * ` noAssert ` {boolean } Skip ` value ` and ` offset ` validation? ** Default:** ` false `
2015
2056
* Returns: {Integer} ` offset ` plus the number of bytes written
2016
2057
2017
2058
Writes ` value ` to ` buf ` at the specified ` offset ` with specified endian
@@ -2044,9 +2085,9 @@ console.log(buf);
2044
2085
added: v0.11.15
2045
2086
-->
2046
2087
2047
- * ` value ` {Number } Number to be written to ` buf `
2088
+ * ` value ` {number } Number to be written to ` buf `
2048
2089
* ` offset ` {Integer} Where to start writing. Must satisfy: ` 0 <= offset <= buf.length - 4 `
2049
- * ` noAssert ` {Boolean } Skip ` value ` and ` offset ` validation? ** Default:** ` false `
2090
+ * ` noAssert ` {boolean } Skip ` value ` and ` offset ` validation? ** Default:** ` false `
2050
2091
* Returns: {Integer} ` offset ` plus the number of bytes written
2051
2092
2052
2093
Writes ` value ` to ` buf ` at the specified ` offset ` with specified endian
@@ -2080,7 +2121,7 @@ added: v0.5.0
2080
2121
2081
2122
* ` value ` {Integer} Number to be written to ` buf `
2082
2123
* ` offset ` {Integer} Where to start writing. Must satisfy: ` 0 <= offset <= buf.length - 1 `
2083
- * ` noAssert ` {Boolean } Skip ` value ` and ` offset ` validation? ** Default:** ` false `
2124
+ * ` noAssert ` {boolean } Skip ` value ` and ` offset ` validation? ** Default:** ` false `
2084
2125
* Returns: {Integer} ` offset ` plus the number of bytes written
2085
2126
2086
2127
Writes ` value ` to ` buf ` at the specified ` offset ` . ` value ` * should* be a valid
@@ -2112,7 +2153,7 @@ added: v0.5.5
2112
2153
2113
2154
* ` value ` {Integer} Number to be written to ` buf `
2114
2155
* ` offset ` {Integer} Where to start writing. Must satisfy: ` 0 <= offset <= buf.length - 2 `
2115
- * ` noAssert ` {Boolean } Skip ` value ` and ` offset ` validation? ** Default:** ` false `
2156
+ * ` noAssert ` {boolean } Skip ` value ` and ` offset ` validation? ** Default:** ` false `
2116
2157
* Returns: {Integer} ` offset ` plus the number of bytes written
2117
2158
2118
2159
Writes ` value ` to ` buf ` at the specified ` offset ` with specified endian
@@ -2145,7 +2186,7 @@ added: v0.5.5
2145
2186
2146
2187
* ` value ` {Integer} Number to be written to ` buf `
2147
2188
* ` offset ` {Integer} Where to start writing. Must satisfy: ` 0 <= offset <= buf.length - 4 `
2148
- * ` noAssert ` {Boolean } Skip ` value ` and ` offset ` validation? ** Default:** ` false `
2189
+ * ` noAssert ` {boolean } Skip ` value ` and ` offset ` validation? ** Default:** ` false `
2149
2190
* Returns: {Integer} ` offset ` plus the number of bytes written
2150
2191
2151
2192
Writes ` value ` to ` buf ` at the specified ` offset ` with specified endian
@@ -2179,7 +2220,7 @@ added: v0.11.15
2179
2220
* ` value ` {Integer} Number to be written to ` buf `
2180
2221
* ` offset ` {Integer} Where to start writing. Must satisfy: ` 0 <= offset <= buf.length - byteLength `
2181
2222
* ` byteLength ` {Integer} How many bytes to write. Must satisfy: ` 0 < byteLength <= 6 `
2182
- * ` noAssert ` {Boolean } Skip ` value ` , ` offset ` , and ` byteLength ` validation?
2223
+ * ` noAssert ` {boolean } Skip ` value ` , ` offset ` , and ` byteLength ` validation?
2183
2224
** Default:** ` false `
2184
2225
* Returns: {Integer} ` offset ` plus the number of bytes written
2185
2226
@@ -2213,7 +2254,7 @@ added: v0.5.0
2213
2254
2214
2255
* ` value ` {Integer} Number to be written to ` buf `
2215
2256
* ` offset ` {Integer} Where to start writing. Must satisfy: ` 0 <= offset <= buf.length - 1 `
2216
- * ` noAssert ` {Boolean } Skip ` value ` and ` offset ` validation? ** Default:** ` false `
2257
+ * ` noAssert ` {boolean } Skip ` value ` and ` offset ` validation? ** Default:** ` false `
2217
2258
* Returns: {Integer} ` offset ` plus the number of bytes written
2218
2259
2219
2260
Writes ` value ` to ` buf ` at the specified ` offset ` . ` value ` * should* be a
@@ -2245,7 +2286,7 @@ added: v0.5.5
2245
2286
2246
2287
* ` value ` {Integer} Number to be written to ` buf `
2247
2288
* ` offset ` {Integer} Where to start writing. Must satisfy: ` 0 <= offset <= buf.length - 2 `
2248
- * ` noAssert ` {Boolean } Skip ` value ` and ` offset ` validation? ** Default:** ` false `
2289
+ * ` noAssert ` {boolean } Skip ` value ` and ` offset ` validation? ** Default:** ` false `
2249
2290
* Returns: {Integer} ` offset ` plus the number of bytes written
2250
2291
2251
2292
Writes ` value ` to ` buf ` at the specified ` offset ` with specified endian
@@ -2282,7 +2323,7 @@ added: v0.5.5
2282
2323
2283
2324
* ` value ` {Integer} Number to be written to ` buf `
2284
2325
* ` offset ` {Integer} Where to start writing. Must satisfy: ` 0 <= offset <= buf.length - 4 `
2285
- * ` noAssert ` {Boolean } Skip ` value ` and ` offset ` validation? ** Default:** ` false `
2326
+ * ` noAssert ` {boolean } Skip ` value ` and ` offset ` validation? ** Default:** ` false `
2286
2327
* Returns: {Integer} ` offset ` plus the number of bytes written
2287
2328
2288
2329
Writes ` value ` to ` buf ` at the specified ` offset ` with specified endian
@@ -2318,7 +2359,7 @@ added: v0.5.5
2318
2359
* ` value ` {Integer} Number to be written to ` buf `
2319
2360
* ` offset ` {Integer} Where to start writing. Must satisfy: ` 0 <= offset <= buf.length - byteLength `
2320
2361
* ` byteLength ` {Integer} How many bytes to write. Must satisfy: ` 0 < byteLength <= 6 `
2321
- * ` noAssert ` {Boolean } Skip ` value ` , ` offset ` , and ` byteLength ` validation?
2362
+ * ` noAssert ` {boolean } Skip ` value ` , ` offset ` , and ` byteLength ` validation?
2322
2363
** Default:** ` false `
2323
2364
* Returns: {Integer} ` offset ` plus the number of bytes written
2324
2365
0 commit comments