|
1 |
| -# Ginkgoch Buffer Reader for NodeJS |
2 |
| -This is a NodeJS library to help to read [Buffer](https://cn.nodejs.org/api/buffer.html) instance easily. |
| 1 | +# Ginkgoch Buffer IO for NodeJS |
| 2 | +This is a NodeJS library to help to read/write [Buffer](https://cn.nodejs.org/api/buffer.html) instance easily. |
3 | 3 |
|
4 | 4 | ## Install
|
5 | 5 | ```terminal
|
6 |
| -npm i ginkgoch-buffer-reader --save |
| 6 | +npm i ginkgoch-buffer-io --save |
7 | 7 | ```
|
8 | 8 |
|
9 | 9 | ## Test
|
10 | 10 | ```terminal
|
11 | 11 | npm test
|
12 | 12 | ```
|
13 | 13 |
|
14 |
| -## Example |
| 14 | +## BufferReader Example |
15 | 15 |
|
16 |
| -**Prepare for data** |
| 16 | +**Without `Ginkgoch Buffer I/O`** |
17 | 17 | ```js
|
18 |
| -const buffer = Buffer.alloc(4); |
| 18 | +const buffer = Buffer.alloc(16); |
19 | 19 | buffer.writeInt8(8, 0);
|
20 | 20 | buffer.writeInt16LE(16, 1);
|
21 | 21 | buffer.writeUInt32LE(32, 3);
|
22 | 22 | buffer.writeDoubleBE(54.8765, 7);
|
23 |
| -``` |
24 | 23 |
|
25 |
| -**Without `Ginkgoch Buffer Reader`** |
26 |
| -```js |
27 | 24 | let i1 = buffer.readInt8(0);
|
28 | 25 | let i2 = buffer.readInt16LE(1);
|
29 | 26 | let i3 = buffer.readUInt32LE(3);
|
30 | 27 | let i4 = buffer.readDoubleBE(7);
|
31 | 28 | ```
|
32 | 29 |
|
33 |
| -**With `Ginkgoch Buffer Reader`** |
| 30 | +**With `Ginkgoch Buffer I/O`** |
34 | 31 | It automatically manages the read position for you. You don't need to remember the position and the boring type length calculations.
|
35 | 32 | ```js
|
36 |
| -const BufferReader = require('ginkgoch-buffer-reader'); |
37 |
| -let br = new BufferReader(buffer); |
| 33 | +const { BufferReader, BufferWriter } = require('ginkgoch-buffer-io'); |
| 34 | + |
| 35 | +const buffer = Buffer.alloc(16); |
| 36 | +const bw = new BufferWriter(buffer); |
| 37 | +bw.writeInt8(8); |
| 38 | +bw.writeInt16(16); |
| 39 | +bw.writeUInt32(32); |
| 40 | +bw.writeDoubleBE(54.8765); |
| 41 | + |
| 42 | +const br = new BufferReader(buffer); |
38 | 43 | let i1 = br.nextInt8();
|
39 |
| -let i2 = br.nextInt16LE(); |
40 |
| -let i3 = br.nextUInt32LE(); |
| 44 | +let i2 = br.nextInt16(); |
| 45 | +let i3 = br.nextUInt32(); |
41 | 46 | let i4 = br.nextDoubleBE();
|
42 | 47 | ```
|
43 | 48 |
|
44 |
| -## API |
45 |
| -```js |
46 |
| -constructor(buffer: Buffer); |
47 |
| -seek(offset: number, fromBeginning = true); |
48 |
| -nextBuffer(length: number); |
49 |
| -nextString(length: number, encoding = 'utf-8'); |
50 |
| -nextIn8(); |
51 |
| -nextUInt8(); |
52 |
| -nextUInt16LE(); |
53 |
| -nextUInt16BE(); |
54 |
| -nextInt16LE(); |
55 |
| -nextInt16BE(); |
56 |
| -nextUInt32LE(); |
57 |
| -nextUInt32BE(); |
58 |
| -nextInt32LE(); |
59 |
| -nextInt32BE(); |
60 |
| -nextFloatLE(); |
61 |
| -nextFloatBE(); |
62 |
| -nextDoubleLE(); |
63 |
| -nextDoubleBE(); |
64 |
| -``` |
| 49 | +## BufferReader |
| 50 | +* constructor(buffer: Buffer) |
| 51 | +* seek(offset: number, fromBeginning = true) |
| 52 | +* nextBuffer(length: number) |
| 53 | +* nextString(length: number, encoding = 'utf-8') |
| 54 | +* nextInt8() |
| 55 | +* nextUInt8() |
| 56 | +* nextUInt16() |
| 57 | +* nextUInt16LE() |
| 58 | +* nextUInt16BE() |
| 59 | +* nextInt16() |
| 60 | +* nextInt16LE() |
| 61 | +* nextInt16BE() |
| 62 | +* nextUInt32() |
| 63 | +* nextUInt32LE() |
| 64 | +* nextUInt32BE() |
| 65 | +* nextInt32() |
| 66 | +* nextInt32LE() |
| 67 | +* nextInt32BE() |
| 68 | +* nextFloat() |
| 69 | +* nextFloatLE() |
| 70 | +* nextFloatBE() |
| 71 | +* nextDouble() |
| 72 | +* nextDoubleLE() |
| 73 | +* nextDoubleBE() |
| 74 | + |
| 75 | +## BufferWriter |
| 76 | +* constructor(buffer: Buffer) |
| 77 | +* seek(offset: number[, fromBeginning = true]) |
| 78 | +* writeBuffer(length: number) |
| 79 | +* writeString(length: number[, encoding = 'utf-8']) |
| 80 | +* writeInt8() |
| 81 | +* writeUInt8() |
| 82 | +* writeUInt16() |
| 83 | +* writeUInt16LE() |
| 84 | +* writeUInt16BE() |
| 85 | +* writeInt16() |
| 86 | +* writeInt16LE() |
| 87 | +* writeInt16BE() |
| 88 | +* writeUInt32() |
| 89 | +* writeUInt32LE() |
| 90 | +* writeUInt32BE() |
| 91 | +* writeInt32() |
| 92 | +* writeInt32LE() |
| 93 | +* writeInt32BE() |
| 94 | +* writeFloat() |
| 95 | +* writeFloatLE() |
| 96 | +* writeFloatBE() |
| 97 | +* writeDouble() |
| 98 | +* writeDoubleLE() |
| 99 | +* writeDoubleBE() |
65 | 100 |
|
66 | 101 | ## Issues
|
67 | 102 | Contact [ginkgoch@outlook.com](mailto:ginkgoch@outlook.com) or [sumbit an issue](https://github.com/ginkgoch/node-buffer-reader/issues).
|
0 commit comments