Skip to content

Commit 34a6454

Browse files
ronagaduh95
authored andcommitted
buffer: add end parameter
To limit how far into the buffer we search without allocating an unnecessary subarray. Signed-off-by: Robert Nagy <ronay@icloud.com> PR-URL: #62390 Reviewed-By: Matteo Collina <matteo.collina@gmail.com> Reviewed-By: Antoine du Hamel <duhamelantoine1995@gmail.com>
1 parent 450e051 commit 34a6454

5 files changed

Lines changed: 195 additions & 58 deletions

File tree

doc/api/buffer.md

Lines changed: 21 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2069,11 +2069,14 @@ console.log(buf.fill('zz', 'hex'));
20692069
// Throws an exception.
20702070
```
20712071

2072-
### `buf.includes(value[, byteOffset][, encoding])`
2072+
### `buf.includes(value[, start[, end]][, encoding])`
20732073

20742074
<!-- YAML
20752075
added: v5.3.0
20762076
changes:
2077+
- version: REPLACEME
2078+
pr-url: https://github.com/nodejs/node/pull/62390
2079+
description: Added the `end` parameter.
20772080
- version:
20782081
- v25.5.0
20792082
- v24.13.1
@@ -2082,8 +2085,10 @@ changes:
20822085
-->
20832086

20842087
* `value` {string|Buffer|Uint8Array|integer} What to search for.
2085-
* `byteOffset` {integer} Where to begin searching in `buf`. If negative, then
2088+
* `start` {integer} Where to begin searching in `buf`. If negative, then
20862089
offset is calculated from the end of `buf`. **Default:** `0`.
2090+
* `end` {integer} Where to stop searching in `buf` (exclusive). **Default:**
2091+
`buf.length`.
20872092
* `encoding` {string} If `value` is a string, this is its encoding.
20882093
**Default:** `'utf8'`.
20892094
* Returns: {boolean} `true` if `value` was found in `buf`, `false` otherwise.
@@ -2132,11 +2137,14 @@ console.log(buf.includes('this', 4));
21322137
// Prints: false
21332138