You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: README.md
+25Lines changed: 25 additions & 0 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -69,6 +69,8 @@ yarn add dynamic-buffer
69
69
70
70
-[Iteration](#iteration)
71
71
72
+
-[Search](#search)
73
+
72
74
-[Comparison](#comparison)
73
75
74
76
-[Export Data](#export-data)
@@ -145,6 +147,17 @@ console.log(buf.toString());
145
147
146
148
-`keys()` returns an iterator of buffer keys (indices).
147
149
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
+
148
161
### Comparison
149
162
150
163
You can compare `DynamicBuffer` object with another `DynamicBuffer` object, Node.js builtin `Buffer` object, or an `Uint8Array` by `compare` or `equals` methods.
0 commit comments