Skip to content

Commit cdbee18

Browse files
committed
doc: update readme.
1 parent 8c34c04 commit cdbee18

File tree

1 file changed

+25
-0
lines changed

1 file changed

+25
-0
lines changed

README.md

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -69,6 +69,8 @@ yarn add dynamic-buffer
6969

7070
- [Iteration](#iteration)
7171

72+
- [Search](#search)
73+
7274
- [Comparison](#comparison)
7375

7476
- [Export Data](#export-data)
@@ -145,6 +147,17 @@ console.log(buf.toString());
145147

146148
- `keys()` returns an iterator of buffer keys (indices).
147149

150+
## Search
151+
152+
You can search a value in the buffer by `indexOf` or `lastIndexOf`, and get the position of the first/last occurrence in the buffer. The searching value can be a string, a number, a `Buffer`, an `Uint8Array`, or another `DynamicBuffer`.
153+
154+
```ts
155+
buf.append('ABCABCABC');
156+
buf.indexOf('ABC'); // 0
157+
buf.lastIndexOf('ABC'); // 6
158+
buf.indexOf('abc'); // -1
159+
```
160+
148161
### Comparison
149162

150163
You can compare `DynamicBuffer` object with another `DynamicBuffer` object, Node.js builtin `Buffer` object, or an `Uint8Array` by `compare` or `equals` methods.
@@ -230,6 +243,18 @@ console.log(buf.toString('utf8', 6, 11));
230243

231244
Return a JSON representation object.
232245

246+
- `includes(value: string | Buffer | Uint8Array | number | DynamicBuffer, byteOffset?: number, encoding?: BufferEncoding): boolean`
247+
248+
Returns a boolean value to indicate whether this buffer includes a certain value among it.
249+
250+
- `indexOf(value: string | Buffer | Uint8Array | number | DynamicBuffer, byteOffset?: number, encoding?: BufferEncoding): number`
251+
252+
Gets the first index at which the given value can be found in the buffer, or `-1` if it is not present.
253+
254+
- `lastIndexOf(value: string | Buffer | Uint8Array | number | DynamicBuffer, byteOffset?: number, encoding?: BufferEncoding): number`
255+
256+
Gets the last index at which the given value can be found in the buffer, or `-1` if it is not present.
257+
233258
- `compare(target: DynamicBuffer | Buffer | Uint8Array, targetStart?: number, targetEnd?: number, sourceStart?: number, sourceEnd?: number)`
234259

235260
Compares two buffers and returns a number indicating whether this buffer comes before, after, or is the same as another buffer in sort order.

0 commit comments

Comments
 (0)