Skip to content

Commit 27f5460

Browse files
committed
docs: update readme.
1 parent 3850e59 commit 27f5460

File tree

1 file changed

+25
-56
lines changed

1 file changed

+25
-56
lines changed

README.md

Lines changed: 25 additions & 56 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
[![Codacy Badge](https://app.codacy.com/project/badge/Grade/210eeb335c0a441ea463872fcd4b4569)](https://www.codacy.com/gh/ghosind/node-dynamic-buffer/dashboard?utm_source=github.com&utm_medium=referral&utm_content=ghosind/node-dynamic-buffer&utm_campaign=Badge_Grade)
88
[![License](https://img.shields.io/github/license/ghosind/node-dynamic-buffer)](https://github.com/ghosind/node-dynamic-buffer)
99

10-
Dynamic storage size buffer object based on Node.js builtin [`Buffer`](https://nodejs.org/api/buffer.html).
10+
An automatically resizing storage size buffer type for Node.js that is based on Node.js builtin [`Buffer`](https://nodejs.org/api/buffer.html).
1111

1212
## Installation
1313

@@ -67,6 +67,8 @@ yarn add dynamic-buffer
6767

6868
- [Write Data](#write-data)
6969

70+
- [Read Data](#read-data)
71+
7072
- [Iteration](#iteration)
7173

7274
- [Search](#search)
@@ -75,7 +77,7 @@ yarn add dynamic-buffer
7577

7678
- [Export Data](#export-data)
7779

78-
- [APIs](#apis)
80+
- [Utils](#utils)
7981

8082
- [Run Tests](#run-tests)
8183

@@ -113,6 +115,17 @@ console.log(buf.toString());
113115
// Hello Node.js
114116
```
115117

118+
### Read Data
119+
120+
You can access the byte at the specified position in the buffer by `read` or `at` methods:
121+
122+
```ts
123+
const buf = new DynamicBuffer('Hello world');
124+
125+
buf.at(0); // 72
126+
buf.read(1); // 101
127+
```
128+
116129
### Iteration
117130

118131
`DynamicBuffer` provides three ways to iterate data from the specified buffer, you can use them with `for...of` statement.
@@ -147,7 +160,7 @@ console.log(buf.toString());
147160

148161
- `keys()` returns an iterator of buffer keys (indices).
149162

150-
## Search
163+
### Search
151164

152165
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`.
153166

@@ -205,63 +218,19 @@ console.log(buf.toString('utf8', 6, 11));
205218
// world
206219
```
207220

208-
## APIs
209-
210-
- `append(data: string, length?: number, encoding?: BufferEncoding): number`
211-
212-
Append string into buffer.
213-
214-
- `write(data: string, offset?: number, length?: number, encoding?: BufferEncoding): number`
215-
216-
Write string into buffer at the specified position.
217-
218-
- `read(offset?: number): number`
219-
220-
Read a byte at the specified position in the buffer.
221-
222-
- `entries(): IterableIterator<[number, number]>`
223-
224-
Get an iterator of index-byte pairs from the buffer.
225-
226-
- `keys(): IterableIterator<number>`
227-
228-
Get an iterator of indices in the buffer.
221+
### Utils
229222

230-
- `values(): IterableIterator<number>`
223+
We provided `isDynamicBuffer` function to indicating an object is a DynamicBuffer object or not.
231224

232-
Get an iterator of data in the buffer.
233-
234-
- `toString(encoding?: BufferEncoding, start?: number, end?: number): string`
235-
236-
Decode buffer to a string.
237-
238-
- `toBuffer(start?: number, end?: number): Buffer`
239-
240-
Return a new builtin Buffer object.
241-
242-
- `toJSON(): { type: string, data: number[] }`
243-
244-
Return a JSON representation object.
245-
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-
258-
- `compare(target: DynamicBuffer | Buffer | Uint8Array, targetStart?: number, targetEnd?: number, sourceStart?: number, sourceEnd?: number)`
259-
260-
Compares two buffers and returns a number indicating whether this buffer comes before, after, or is the same as another buffer in sort order.
225+
```ts
226+
import { isDynamicBuffer } from 'dynamic-buffer';
261227

262-
- `equals(otherBuffer: DynamicBuffer | Buffer | Uint8Array): boolean`
228+
const buf1 = Buffer.alloc(8);
229+
const buf2 = new DynamicBuffer();
263230

264-
Compares and returns a boolean value. Returns `true` if two buffers have exactly the same bytes, `false` otherwise.
231+
isDynamicBuffer(buf1); // false
232+
isDynamicBuffer(buf2); // true
233+
```
265234

266235
## Run Tests
267236

0 commit comments

Comments
 (0)