bireader 4.0.0 → 4.0.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +327 -245
- package/_test_reader.cjs +38 -0
- package/_test_writer.mjs +8 -0
- package/dist/index.browser.d.ts +8491 -1354
- package/dist/index.browser.js +16026 -4182
- package/dist/index.browser.js.map +1 -1
- package/dist/index.cjs.d.ts +1813 -7009
- package/dist/index.cjs.js +7532 -18774
- package/dist/index.cjs.js.map +1 -1
- package/dist/index.d.ts +1813 -7009
- package/dist/index.esm.d.ts +1813 -7009
- package/dist/index.esm.js +7533 -18773
- package/dist/index.esm.js.map +1 -1
- package/package.json +9 -3
package/README.md
CHANGED
|
@@ -1,8 +1,35 @@
|
|
|
1
1
|
# BiReader / BiWriter
|
|
2
2
|
|
|
3
|
-
A
|
|
3
|
+
**A fast, dual-mode (sync / async) file / buffer handler with byte + bit-level access.**
|
|
4
4
|
|
|
5
|
-
|
|
5
|
+
Feature rich binary reader ***and writer*** that keeps track of your position to quickly create file structures. Perfect for binary parsers, editors, game save files, custom formats, or any situation where you need random access + structural modifications without loading the entire file into memory. Includes shared naming conventions, programmable inputs and advanced math for easy data conversions on low level parsing. Accepts `Uint8Array`, `Buffer` or a `filePath`. Includes Sync and [Async](#async) verions.
|
|
6
|
+
|
|
7
|
+
---
|
|
8
|
+
|
|
9
|
+
## ✨ Features
|
|
10
|
+
|
|
11
|
+
- **Dual mode**: Sync or Async file reader (`r+` / `r`) on disk **or** pure in-memory `Buffer` or `Uint8Array`
|
|
12
|
+
- **Chunked async loading** – configurable `windowSize` (default 4 KiB)
|
|
13
|
+
→ Set `windowSize: 0` to load the entire file in **one** async read
|
|
14
|
+
- **Byte cursor**: Track and change location with `offset` +Bit cursor `bitOffset`
|
|
15
|
+
- **Full bitfield support** – `readBit()` / `writeBit()` with:
|
|
16
|
+
- signed / unsigned
|
|
17
|
+
- big-endian (`'be'`) or little-endian (`'le'`)
|
|
18
|
+
- any alignment (bits can start anywhere)
|
|
19
|
+
- **Structural edits**:
|
|
20
|
+
- `insert()` – insert data anywhere
|
|
21
|
+
- `remove()` – delete data and **return** the removed chunk
|
|
22
|
+
- `trim()` – shrink (returns removed tail)
|
|
23
|
+
- `push()` – Grows start
|
|
24
|
+
- **Expandable files** with smart `growthIncrement` (default 1 MiB) to minimize syscalls
|
|
25
|
+
- `return()` – flushes changes and returns the complete current content
|
|
26
|
+
- `readonly` and `strict` modes (for limiting `growthIncrement`)
|
|
27
|
+
- In `async` class, all operations automatically wait for required chunks
|
|
28
|
+
- Zero dependencies (only `fs` & `fs/promises` in Node)
|
|
29
|
+
|
|
30
|
+
---
|
|
31
|
+
|
|
32
|
+
## ✅ Supported data types
|
|
6
33
|
|
|
7
34
|
- [Bitfields](#bit-field) ([u]bit{1-32}{le|be}) 1-32 bit signed or unsigned value in big or little endian order
|
|
8
35
|
- [Bytes](#byte) ([u]int8, byte) 8 bit signed or unsigned value
|
|
@@ -14,13 +41,15 @@ Supported data types:
|
|
|
14
41
|
- [Double Floats](#double-float) (doublefloat, dfloat{le|be}) 64 bit decimal value in big or little endian
|
|
15
42
|
- [Strings](#strings) (string) Fixed and non-fixed length, UTF, pascal, wide pascal. Includes all `TextEncoder` types
|
|
16
43
|
|
|
17
|
-
## What's New?
|
|
44
|
+
## ⭐ What's New?
|
|
18
45
|
|
|
19
46
|
### v4
|
|
47
|
+
* Added `BiReaderAsync` and `BiWriterAsync`. See [Async](#async) classes.
|
|
20
48
|
* Uses `DataView` read and write functions when possible for more efficient code (previous code is now fallback).
|
|
21
|
-
*
|
|
22
|
-
*
|
|
23
|
-
*
|
|
49
|
+
* Added support for `UTF-32` and `Double Wide Pascal` (32 bit) strings.
|
|
50
|
+
* Large code clean up with included test.
|
|
51
|
+
* Marked deprecated `BiReaderStream` and `BiWriterStream` as functionality was moved to `BiReader` and `BiWriter` for file reading (Node only).
|
|
52
|
+
* Values for writes are now clamped to bit size and don't throw errors.
|
|
24
53
|
|
|
25
54
|
### v3
|
|
26
55
|
* Added `enforceBigInt` option for always returning a `BigInt` type on 64 bit reads, otherwise will return a `number` if integer safe.
|
|
@@ -28,7 +57,7 @@ Supported data types:
|
|
|
28
57
|
* Added new `BiReaderStream` and `BiWriterStream` (Node only).
|
|
29
58
|
* Added `.deleteFile()` and `.renameFile(filePath)`.
|
|
30
59
|
* Added setter `.strSettings` for use with `.str` for easier coding.
|
|
31
|
-
* Added better options for extending array buffer when writing data with `
|
|
60
|
+
* Added better options for extending array buffer when writing data with `growthIncrement`.
|
|
32
61
|
* Consolidated all options argument into single object when creating class.
|
|
33
62
|
* Removed deprecated `bireader` and `biwriter` classes.
|
|
34
63
|
* Fixed standalone `hexdump` function.
|
|
@@ -45,9 +74,118 @@ Supported data types:
|
|
|
45
74
|
|
|
46
75
|
``npm install bireader``
|
|
47
76
|
|
|
48
|
-
Provides both CommonJS and ES modules
|
|
77
|
+
Provides both CommonJS and ES modules. Works in Browser, Node.js (CJS + ESM), and provides zero-dependency binaries.
|
|
78
|
+
|
|
79
|
+
## Quick Start – The 4 Classes
|
|
80
|
+
|
|
81
|
+
| Class | Use Case | Style | Best For |
|
|
82
|
+
| --- | --- | --- | --- |
|
|
83
|
+
|`BiReader` | Most parsing tasks | Sync | Buffers + normal files |
|
|
84
|
+
|`BiWriter` | Creating / editing binary files | Sync | In-memory + normal files |
|
|
85
|
+
|`BiReaderAsync`| Huge files (> 2–4 GB) | Async | Very large files |
|
|
86
|
+
|`BiWriterAsync`| Writing huge files without OOM | Async | Streaming / large output |
|
|
87
|
+
|
|
88
|
+
### 1. BiReader + BiWriter (Sync – Recommended for 99% of use cases)
|
|
89
|
+
|
|
90
|
+
```javascript
|
|
91
|
+
import { BiReader, BiWriter } from 'bireader';
|
|
92
|
+
|
|
93
|
+
// === Reading from Buffer / Uint8Array ===
|
|
94
|
+
const data = new Uint8Array([0x01, 0x02, 0x03, 0x04 /* ... */]);
|
|
95
|
+
const br = new BiReader(data);
|
|
96
|
+
|
|
97
|
+
console.log(br.uint32le); // auto-advances cursor
|
|
98
|
+
console.log(br.halffloatle);
|
|
99
|
+
console.log(br.readString(10)); // or use .pstring2le, .widestring, etc.
|
|
100
|
+
|
|
101
|
+
// === Writing (auto-grows) ===
|
|
102
|
+
const bw = new BiWriter();
|
|
103
|
+
bw.uint32le = 0xCAFEBABE;
|
|
104
|
+
bw.halffloatle = 3.1416;
|
|
105
|
+
bw.pstring2le("Hello World");
|
|
106
|
+
bw.writeBit(0b101, 3); // bit-level control
|
|
107
|
+
|
|
108
|
+
const finalBuffer = bw.data; // or bw.toBuffer()
|
|
109
|
+
```
|
|
110
|
+
**Node.js file support (still sync)**
|
|
111
|
+
|
|
112
|
+
```javascript
|
|
113
|
+
const brFile = new BiReader('huge-but-not-gigantic.bin'); // accepts filePath
|
|
114
|
+
console.log(brFile.int64le);
|
|
115
|
+
```
|
|
116
|
+
|
|
117
|
+
### 2. BiReaderAsync + BiWriterAsync (Async – for huge files)
|
|
118
|
+
|
|
119
|
+
```javascript
|
|
120
|
+
import { BiReaderAsync, BiWriterAsync } from 'bireader';
|
|
121
|
+
|
|
122
|
+
// === Async Reader (random access, no full load into RAM) ===
|
|
123
|
+
const brAsync = await BiReaderAsync.create('massive-50gb-file.bin');
|
|
124
|
+
|
|
125
|
+
await brAsync.seek(1024 * 1024 * 1024); // jump to 1 GB mark
|
|
126
|
+
const magic = await brAsync.str(); // or .uint32le, .halffloatle, etc.
|
|
127
|
+
const value = await brAsync.readUint64(); // all methods are now async
|
|
128
|
+
|
|
129
|
+
await brAsync.close();
|
|
130
|
+
```
|
|
131
|
+
|
|
132
|
+
**Async Writer**
|
|
133
|
+
|
|
134
|
+
```javascript
|
|
135
|
+
const bwAsync = await BiWriterAsync.create('output-huge.bin');
|
|
136
|
+
|
|
137
|
+
await bwAsync.writeUint32(0xDEADBEEF);
|
|
138
|
+
await bwAsync.halffloatle(1.618);
|
|
139
|
+
await bwAsync.writeString("Header data", { stringType: 'utf8', terminateValue: 0 });
|
|
140
|
+
|
|
141
|
+
await bwAsync.close(); // flushes everything
|
|
142
|
+
```
|
|
143
|
+
|
|
144
|
+
**Important: `BiReaderAsync` / `BiWriterAsync` are Node.js only (they use `fs/promises`).**
|
|
49
145
|
|
|
50
|
-
### Example
|
|
146
|
+
### 3. Bit-Field Example (works on all 4 classes)
|
|
147
|
+
|
|
148
|
+
```javascript
|
|
149
|
+
const br = new BiReader(myData);
|
|
150
|
+
br.goto(0x100);
|
|
151
|
+
|
|
152
|
+
// Bit-level presets (auto-advance cursor)
|
|
153
|
+
console.log(br.ubit4); // 4 bits
|
|
154
|
+
console.log(br.bit8); // signed 8 bits
|
|
155
|
+
console.log(br.ubit24be); // 24 bits big-endian
|
|
156
|
+
|
|
157
|
+
// Manual bit control
|
|
158
|
+
br.insetBit = 3;
|
|
159
|
+
console.log(br.readBit(5)); // read any number of bits
|
|
160
|
+
br.writeBit(0b10110, 5); // write any number of bits
|
|
161
|
+
```
|
|
162
|
+
|
|
163
|
+
### 4. String Handling (all variants)
|
|
164
|
+
|
|
165
|
+
```javascript
|
|
166
|
+
const bw = new BiWriter();
|
|
167
|
+
bw.strSettings = { length: 8, stringType: 'utf16le', terminateValue: 0 };
|
|
168
|
+
|
|
169
|
+
bw.str = "Hello 🌍"; // uses current strSettings
|
|
170
|
+
bw.pstring2le("Pascal string");
|
|
171
|
+
bw.widestring("UTF-16 wide string");
|
|
172
|
+
|
|
173
|
+
const br = new BiReader(bw.data);
|
|
174
|
+
console.log(br.cstring()); // null-terminated
|
|
175
|
+
console.log(br.pstring4be());
|
|
176
|
+
```
|
|
177
|
+
|
|
178
|
+
### 5. Math Helpers (XOR, shifts, etc.)
|
|
179
|
+
|
|
180
|
+
```javascript
|
|
181
|
+
const bw = new BiWriter(data);
|
|
182
|
+
bw.xor(0xAA); // XOR entire buffer with key
|
|
183
|
+
bw.lShift(1, 0, 8); // left-shift first 8 bytes by 1 bit
|
|
184
|
+
bw.and(0x0F, 0, 4); // AND bytes 0-3 with 0x0F
|
|
185
|
+
console.log(bw.toHex()); // nice hexdump helper
|
|
186
|
+
```
|
|
187
|
+
|
|
188
|
+
### 6. Real-World Complete Example (WebP parser)
|
|
51
189
|
|
|
52
190
|
<details>
|
|
53
191
|
<summary>Click to expand</summary>
|
|
@@ -60,7 +198,7 @@ Includes presents for quick parsing or programmable functions (examples below).
|
|
|
60
198
|
import {BiReader, BiWriter} from 'bireader';
|
|
61
199
|
|
|
62
200
|
// read example - parse a webp file
|
|
63
|
-
function
|
|
201
|
+
function parseWebp(data){
|
|
64
202
|
const br = new BiReader(data);
|
|
65
203
|
br.strSettings = {length: 4};
|
|
66
204
|
br.hexdump({suppressUnicode:true}); // console.log data as hex
|
|
@@ -89,9 +227,9 @@ function parse_webp(data){
|
|
|
89
227
|
switch (header.format){
|
|
90
228
|
case "VP8 ":
|
|
91
229
|
header.formatType = "Lossy";
|
|
92
|
-
var
|
|
230
|
+
var readSize = 0;
|
|
93
231
|
header.frame_tag = br.ubit24;
|
|
94
|
-
|
|
232
|
+
readSize += 3;
|
|
95
233
|
header.key_frame = header.frame_tag & 0x1;
|
|
96
234
|
header.version = (header.frame_tag >> 1) & 0x7;
|
|
97
235
|
header.show_frame = (header.frame_tag >> 4) & 0x1;
|
|
@@ -103,22 +241,22 @@ function parse_webp(data){
|
|
|
103
241
|
header.vertical_size_code = br.ubit16;
|
|
104
242
|
header.height = header.vertical_size_code & 0x3FFF;
|
|
105
243
|
header.vertical_scale = header.vertical_size_code >> 14;
|
|
106
|
-
|
|
107
|
-
header.VP8data = br.extract(header.formatChunkSize -
|
|
244
|
+
readSize += 7;
|
|
245
|
+
header.VP8data = br.extract(header.formatChunkSize - readSize, true);
|
|
108
246
|
break;
|
|
109
247
|
case "VP8L":
|
|
110
248
|
header.formatType = "Lossless";
|
|
111
|
-
var
|
|
249
|
+
var readSize = 0;
|
|
112
250
|
header.signature = br.ubyte; // should be 47
|
|
113
|
-
|
|
251
|
+
readSize += 1;
|
|
114
252
|
header.readWidth = br.ubit14;
|
|
115
253
|
header.width = header.readWidth+1;
|
|
116
254
|
header.readHeight = br.ubit14;
|
|
117
255
|
header.height = header.readHeight+1;
|
|
118
256
|
header.alpha_is_used = br.bit1;
|
|
119
257
|
header.version_number = br.ubit3;
|
|
120
|
-
|
|
121
|
-
header.VP8Ldata = br.extract(header.formatChunkSize -
|
|
258
|
+
readSize += 4;
|
|
259
|
+
header.VP8Ldata = br.extract(header.formatChunkSize - readSize, true);
|
|
122
260
|
break;
|
|
123
261
|
case "VP8X":
|
|
124
262
|
header.formatType = "Extended";
|
|
@@ -308,6 +446,8 @@ function write_webp(data){
|
|
|
308
446
|
|
|
309
447
|
Common functions for setup, movement, manipulation and math shared by both.
|
|
310
448
|
|
|
449
|
+
Naming is shared across sync and async classes.
|
|
450
|
+
|
|
311
451
|
<table>
|
|
312
452
|
<thead>
|
|
313
453
|
<tr>
|
|
@@ -322,15 +462,53 @@ Common functions for setup, movement, manipulation and math shared by both.
|
|
|
322
462
|
<tr>
|
|
323
463
|
<tr>
|
|
324
464
|
<td>Class</td>
|
|
325
|
-
<td>new BiReader(<b>dataOrPath</b>, {byteOffset, bitOffset, endianess, strict,
|
|
326
|
-
<td
|
|
465
|
+
<td>new BiReader(<b>dataOrPath</b>, {byteOffset, bitOffset, endianess, strict, growthIncrement, enforceBigInt, readOnly})</td>
|
|
466
|
+
<td rowspan="2"><b>dataOrPath:</b> string path or Buffer or Uint8Array</b><br><b>byteOffset:</b> byte offset (default <code>0</code>)<br><b>bitOffset:</b> bit offset (overides <code>byteOffset</code>) (default <code>0</code>)<br><b>endianess:</b> endian big or little (default <code>little</code>)<br><b>strict:</b> strict mode restrict extending initially supplied data (default <code>true</code> for reader, <code>false</code> for writer)<br><b>growthIncrement:</b> default extended Buffer size (default <code>1 MiB</code>)<br><b>enforceBigInt:</b> always return <code>bigint</code> values on 64 bit reads (default <code>false</code>)<br><b>readOnly:</b> read only Buffer or file (default <code>true</code> in writer)
|
|
327
467
|
</td>
|
|
328
|
-
<td rowspan="2">Start with new Constructor.<br><br><b>File Note:</b> When writing to a file, you must use close() when finished, or commit() to make sure changes are committed
|
|
468
|
+
<td rowspan="2">Start with new Constructor.<br><br><b>File Note:</b> When writing to a file, you must use close() when finished, or commit() to make sure changes are committed.<br><br><b>Data Note:</b> Supplied data can always be found with <b>.data</b>.<br><br><b>Supplied data note:</b> While BiWriter can be created with a 0 length Uint8Array or Buffer, the default <code>growthIncrement</code> will prevent a new array created on each operation (leading to a degraded performance). It's best to supply a larger than needed buffer when creating the Writer and use <b>.trim()</b> after you're finished.</td>
|
|
329
469
|
</tr>
|
|
330
470
|
<tr>
|
|
331
471
|
<td>Class</td>
|
|
332
|
-
<td>new BiWriter(<b>dataOrPath</b>, {byteOffset, bitOffset, endianess, strict,
|
|
472
|
+
<td>new BiWriter(<b>dataOrPath</b>, {byteOffset, bitOffset, endianess, strict, growthIncrement, enforceBigInt, writeable})</td>
|
|
333
473
|
</tr>
|
|
474
|
+
<th align="center" colspan="4"><i>File Mode</i></th>
|
|
475
|
+
<tr>
|
|
476
|
+
<td>Function</td>
|
|
477
|
+
<td>open()
|
|
478
|
+
<td align="center"><b>none</td>
|
|
479
|
+
<td>Opens file for reading / writing. Happens before any operations.</td>
|
|
480
|
+
</tr>
|
|
481
|
+
<tr>
|
|
482
|
+
<td>Function</td>
|
|
483
|
+
<td>close()
|
|
484
|
+
<td align="center"><b>none</td>
|
|
485
|
+
<td>Closes file after reading / writing. Note: Commits any edits to the file.</td>
|
|
486
|
+
</tr>
|
|
487
|
+
<tr>
|
|
488
|
+
<td>Function</td>
|
|
489
|
+
<td>commit()
|
|
490
|
+
<td align="center"><b>none</td>
|
|
491
|
+
<td>Commits any edits to data to file.</td>
|
|
492
|
+
</tr>
|
|
493
|
+
<tr>
|
|
494
|
+
<td>Function</td>
|
|
495
|
+
<td>writeMode(<b>mode</b>)</td>
|
|
496
|
+
<td align="center" >boolean</td>
|
|
497
|
+
<td>Set strict and readOnly to true or false. Will close and reopen file in file mode.</td>
|
|
498
|
+
</tr>
|
|
499
|
+
<tr>
|
|
500
|
+
<td>Function</td>
|
|
501
|
+
<td>renameFile(<b>newFilePath</b>)
|
|
502
|
+
<td align="center"><b>Full path to file to rename.</td>
|
|
503
|
+
<td>Renames the file on the file system, keeps read / write position.<br/><br/><b>Note: This is permanent.</b></td>
|
|
504
|
+
</tr>
|
|
505
|
+
<tr>
|
|
506
|
+
<td>Function</td>
|
|
507
|
+
<td>deleteFile()
|
|
508
|
+
<td align="center"><b>none</td>
|
|
509
|
+
<td>Unlinks the file from the file system.<br/><br/><b>Note: This is permanent, it doesn't send the file to the recycling bin for recovery.</b></td>
|
|
510
|
+
</tr>
|
|
511
|
+
<th align="center" colspan="4"><i>Endian</i></th>
|
|
334
512
|
<tr>
|
|
335
513
|
<td>Function</td>
|
|
336
514
|
<td>endianness(<b>"big" | "little"</b>)</td>
|
|
@@ -341,55 +519,57 @@ Common functions for setup, movement, manipulation and math shared by both.
|
|
|
341
519
|
<td>Presets</td>
|
|
342
520
|
<td>bigEndian(), big(), be()<br>littleEndian(), little(), le()</td>
|
|
343
521
|
</tr>
|
|
522
|
+
<th align="center" colspan="4"><i>Size</i></th>
|
|
344
523
|
<tr>
|
|
345
524
|
<td>get</td>
|
|
346
|
-
<td>
|
|
525
|
+
<td>size</td>
|
|
347
526
|
<td align="center" rowspan="2">None</td>
|
|
348
527
|
<td rowspan="2">Gets the current buffer size in bytes.</td>
|
|
349
528
|
</tr>
|
|
350
529
|
<tr>
|
|
351
530
|
<td>Aliases</td>
|
|
352
|
-
<td>
|
|
531
|
+
<td>length, len, fileSize</td>
|
|
353
532
|
</tr>
|
|
354
533
|
<tr>
|
|
355
534
|
<td>get</td>
|
|
356
|
-
<td>
|
|
535
|
+
<td>sizeBits</td>
|
|
357
536
|
<td align="center" rowspan="2">None</td>
|
|
358
537
|
<td rowspan="2">Gets the current buffer size in bits.</td>
|
|
359
538
|
</tr>
|
|
360
539
|
<tr>
|
|
361
540
|
<td>Aliases</td>
|
|
362
|
-
<td>
|
|
541
|
+
<td>lengthBits, lenBits, fileSizeBits</td>
|
|
363
542
|
</tr>
|
|
543
|
+
<th align="center" colspan="4"><i>Position</i></th>
|
|
364
544
|
<tr>
|
|
365
545
|
<td>get</td>
|
|
366
|
-
<td>
|
|
546
|
+
<td>offset</td>
|
|
367
547
|
<td align="center" rowspan="2">None</td>
|
|
368
548
|
<td rowspan="2">Gets current byte position.</td>
|
|
369
549
|
</tr>
|
|
370
550
|
<tr>
|
|
371
551
|
<td>Aliases</td>
|
|
372
|
-
<td>off, FTell,
|
|
552
|
+
<td>byteOffset, off, FTell, saveOffset</td>
|
|
373
553
|
</tr>
|
|
374
554
|
<tr>
|
|
375
555
|
<td>get</td>
|
|
376
|
-
<td>
|
|
556
|
+
<td>bitOffset</td>
|
|
377
557
|
<td align="center" rowspan="2">None</td>
|
|
378
|
-
<td rowspan="2">Gets current
|
|
558
|
+
<td rowspan="2">Gets current bit position.</td>
|
|
379
559
|
</tr>
|
|
380
560
|
<tr>
|
|
381
561
|
<td>Aliases</td>
|
|
382
|
-
<td>
|
|
562
|
+
<td>offsetBits, offBits, FTellBits, saveBitOffset</td>
|
|
383
563
|
</tr>
|
|
384
564
|
<tr>
|
|
385
565
|
<td>get</td>
|
|
386
|
-
<td>
|
|
566
|
+
<td>insetBit</td>
|
|
387
567
|
<td align="center" rowspan="2">None</td>
|
|
388
|
-
<td rowspan="2">Gets current
|
|
568
|
+
<td rowspan="2">Gets current byte's bit position (0-7).</td>
|
|
389
569
|
</tr>
|
|
390
570
|
<tr>
|
|
391
571
|
<td>Aliases</td>
|
|
392
|
-
<td>
|
|
572
|
+
<td>inBit, bitTell, saveInsetBit</td>
|
|
393
573
|
</tr>
|
|
394
574
|
<tr>
|
|
395
575
|
<td>get</td>
|
|
@@ -403,13 +583,13 @@ Common functions for setup, movement, manipulation and math shared by both.
|
|
|
403
583
|
</tr>
|
|
404
584
|
<tr>
|
|
405
585
|
<td>get</td>
|
|
406
|
-
<td>
|
|
586
|
+
<td>remainBits</td>
|
|
407
587
|
<td align="center" rowspan="2">None</td>
|
|
408
588
|
<td rowspan="2">Size in bits of current read position to the end.</td>
|
|
409
589
|
</tr>
|
|
410
590
|
<tr>
|
|
411
591
|
<td>Aliases</td>
|
|
412
|
-
<td>
|
|
592
|
+
<td>FEoFBits</td>
|
|
413
593
|
</tr>
|
|
414
594
|
<tr>
|
|
415
595
|
<td>get</td>
|
|
@@ -421,43 +601,34 @@ Common functions for setup, movement, manipulation and math shared by both.
|
|
|
421
601
|
<td>Aliases</td>
|
|
422
602
|
<td>row</td>
|
|
423
603
|
</tr>
|
|
604
|
+
<th align="center" colspan="4"><i>Finishing</i></th>
|
|
424
605
|
<tr>
|
|
425
606
|
<td>Function</td>
|
|
426
607
|
<td>get()</td>
|
|
427
608
|
<td align="center" rowspan="2">None</td>
|
|
428
|
-
<td rowspan="2">Returns supplied data. <b>Note:</b> Will use
|
|
609
|
+
<td rowspan="2">Returns supplied data. <b>Note:</b> Will use <code>.trim()</code> function if <code>growthIncrement</code> extended the buffer (removes all data after current position). Use <code>.data</code> if you want the full padded data buffer.</td>
|
|
429
610
|
</tr>
|
|
430
611
|
<tr>
|
|
431
|
-
<td>
|
|
432
|
-
<td>return()</td>
|
|
612
|
+
<td>Aliases</td>
|
|
613
|
+
<td>return(), getFullBuffer()</td>
|
|
433
614
|
</tr>
|
|
615
|
+
<tr>
|
|
616
|
+
<td>Function</td>
|
|
617
|
+
<td>end()</td>
|
|
618
|
+
<td align="center" rowspan="2">None</td>
|
|
619
|
+
<td rowspan="2">Removes supplied data.</td>
|
|
620
|
+
</tr>
|
|
621
|
+
<tr>
|
|
622
|
+
<td>Aliases</td>
|
|
623
|
+
<td>close(), done(), finished()</td>
|
|
624
|
+
</tr>
|
|
434
625
|
<tr>
|
|
435
626
|
<td>get</td>
|
|
436
627
|
<td>data</td>
|
|
437
628
|
<td align="center">None</td>
|
|
438
629
|
<td >Returns full current buffer data.</td>
|
|
439
630
|
</tr>
|
|
440
|
-
<
|
|
441
|
-
<td>set</td>
|
|
442
|
-
<td>enforceBigInt = true</td>
|
|
443
|
-
<td align="center">boolean</td>
|
|
444
|
-
<td >If 64 bit reads always return a <code>bigint</code> or a <code>number</code> when possible</td>
|
|
445
|
-
</tr>
|
|
446
|
-
<tr>
|
|
447
|
-
<td>set</td>
|
|
448
|
-
<td>strSettings = {length?, stringType?, terminateValue?, lengthReadSize?, lengthWriteSize?, stripNull?, encoding?, endian?}</td>
|
|
449
|
-
<td>
|
|
450
|
-
<b>length:</b> Length of string for fixed length, non-terminate value utf strings<br/>
|
|
451
|
-
<b>stringType:</b> <code>utf-8</code>, <code>utf-16</code>, <code>pascal</code> or <code>wide-pascal</code>. Default <code>utf-8</code>.<br/>
|
|
452
|
-
<b>terminateValue:</b> Number only with <code>stringType</code> of utf types.<br/>
|
|
453
|
-
<b>lengthReadSize</b> For pascal strings. 1, 2 or 4 byte length read size. Default <code>1</code><br/>
|
|
454
|
-
<b>lengthWriteSize:</b> For pascal strings. 1, 2 or 4 byte length write size. Default <code>1</code>.<br/>
|
|
455
|
-
<b>stripNull:</b> Removes 0x00 characters. default <code>true</code><br/>
|
|
456
|
-
<b>encoding:</b> TextEncoder accepted types. Default <code>utf-8</code>.<br/>
|
|
457
|
-
<b>endian:</b> <code>big</code> or <code>little</code><br/>
|
|
458
|
-
</td>
|
|
459
|
-
<td >Set universal string settings across all string functions.</td>
|
|
460
|
-
</tr>
|
|
631
|
+
<th align="center" colspan="4"><i>Hex Dump</i></th>
|
|
461
632
|
<tr>
|
|
462
633
|
<td>Function</td>
|
|
463
634
|
<td>hexdump({length, startByte, suppressUnicode})</td>
|
|
@@ -476,6 +647,7 @@ Common functions for setup, movement, manipulation and math shared by both.
|
|
|
476
647
|
<td align="center">None</td>
|
|
477
648
|
<td >Turns on hexdump on error</td>
|
|
478
649
|
</tr>
|
|
650
|
+
<th align="center" colspan="4"><i>Strict</i></th>
|
|
479
651
|
<tr>
|
|
480
652
|
<td>Function</td>
|
|
481
653
|
<td>unrestrict()</td>
|
|
@@ -488,53 +660,7 @@ Common functions for setup, movement, manipulation and math shared by both.
|
|
|
488
660
|
<td align="center">None</td>
|
|
489
661
|
<td>Sets strict mode to true, won't extend array if data is outside of max size (<b>default true for reader, false for writer</b>)</td>
|
|
490
662
|
</tr>
|
|
491
|
-
|
|
492
|
-
<td>Function</td>
|
|
493
|
-
<td>end()</td>
|
|
494
|
-
<td align="center" rowspan="2">None</td>
|
|
495
|
-
<td rowspan="2">Removes supplied data.</td>
|
|
496
|
-
</tr>
|
|
497
|
-
<tr>
|
|
498
|
-
<td>Aliases</td>
|
|
499
|
-
<td>close(), done(), finished()</td>
|
|
500
|
-
</tr>
|
|
501
|
-
<th align="center" colspan="4"><i>File Control</i></th>
|
|
502
|
-
<tr>
|
|
503
|
-
<td>Function</td>
|
|
504
|
-
<td>open()
|
|
505
|
-
<td align="center"><b>none</td>
|
|
506
|
-
<td>Opens file for reading / writing. Happens at class creation.</td>
|
|
507
|
-
</tr>
|
|
508
|
-
<tr>
|
|
509
|
-
<td>Function</td>
|
|
510
|
-
<td>close()
|
|
511
|
-
<td align="center"><b>none</td>
|
|
512
|
-
<td>Closes file after reading / writing. Note: Commits any edits to the file.</td>
|
|
513
|
-
</tr>
|
|
514
|
-
<tr>
|
|
515
|
-
<td>Function</td>
|
|
516
|
-
<td>commit()
|
|
517
|
-
<td align="center"><b>none</td>
|
|
518
|
-
<td>Commits any edits to data to file.</td>
|
|
519
|
-
</tr>
|
|
520
|
-
<tr>
|
|
521
|
-
<td>Function</td>
|
|
522
|
-
<td>writeMode(writable)
|
|
523
|
-
<td align="center"><b>True if you want to switch to writing in BiReader.</td>
|
|
524
|
-
<td>Note: This changes reader to write mode. Allows file to be expanded in size as well.</td>
|
|
525
|
-
</tr>
|
|
526
|
-
<tr>
|
|
527
|
-
<td>Function</td>
|
|
528
|
-
<td>renameFile(<b>newFilePath</b>)
|
|
529
|
-
<td align="center"><b>Full path to file to rename.</td>
|
|
530
|
-
<td>Renames the file on the file system, keeps read / write position.<br/><br/><b>Note: This is permanent.</b></td>
|
|
531
|
-
</tr>
|
|
532
|
-
<tr>
|
|
533
|
-
<td>Function</td>
|
|
534
|
-
<td>deleteFile()
|
|
535
|
-
<td align="center"><b>none</td>
|
|
536
|
-
<td>Unlinks the file from the file system.<br/><br/><b>Note: This is permanent, it doesn't send the file to the recycling bin for recovery.</b></td>
|
|
537
|
-
</tr>
|
|
663
|
+
|
|
538
664
|
<th align="center" colspan="4"><i>Search</i></th>
|
|
539
665
|
<tr>
|
|
540
666
|
<td>Function</td>
|
|
@@ -610,7 +736,7 @@ Common functions for setup, movement, manipulation and math shared by both.
|
|
|
610
736
|
<tr>
|
|
611
737
|
<td>Function</td>
|
|
612
738
|
<td>goto(<b>byte</b>, bit)</td>
|
|
613
|
-
<td align="center" rowspan="2"><b>Byte offset from start</b>,
|
|
739
|
+
<td align="center" rowspan="2"><b>Byte offset from start</b>, bits within byte offset</td>
|
|
614
740
|
<td rowspan="2"><b>Note:</b> Remaining bits are drop when returning to byte function.</td>
|
|
615
741
|
</tr>
|
|
616
742
|
<tr>
|
|
@@ -666,13 +792,13 @@ Common functions for setup, movement, manipulation and math shared by both.
|
|
|
666
792
|
</tr>
|
|
667
793
|
<tr>
|
|
668
794
|
<td>Function</td>
|
|
669
|
-
<td>replace(<b>data</b>,
|
|
795
|
+
<td>replace(<b>data</b>, offset, consume)</td>
|
|
670
796
|
<td align="center" rowspan="2"><b>Data to replace in supplied data</b>, move byte position to after data read (default false), byte position to start replace (default current byte position)</td>
|
|
671
797
|
<td rowspan="2">Replaces data at current byte or supplied offset.<br><b>Note:</b> Errors on strict mode</td>
|
|
672
798
|
</tr>
|
|
673
799
|
<tr>
|
|
674
800
|
<td>Alias</td>
|
|
675
|
-
<td>
|
|
801
|
+
<td>overwrite(<b>data</b>, offset, consume)</td>
|
|
676
802
|
</tr>
|
|
677
803
|
<tr>
|
|
678
804
|
<td>Function</td>
|
|
@@ -696,8 +822,8 @@ Common functions for setup, movement, manipulation and math shared by both.
|
|
|
696
822
|
</tr>
|
|
697
823
|
<tr>
|
|
698
824
|
<td>Function</td>
|
|
699
|
-
<td>insert(<b>data</b>,
|
|
700
|
-
<td align="center" rowspan="2"><b>New data to insert</b>,
|
|
825
|
+
<td>insert(<b>data</b>, offset, consume)</td>
|
|
826
|
+
<td align="center" rowspan="2"><b>New data to insert</b>, byte position to insert (default current byte position), move byte position to after data read (default true)</td>
|
|
701
827
|
<td rowspan="2">Inserts new data into supplied data. <b>Note:</b> Data type must match supplied data. Errors on strict mode</td>
|
|
702
828
|
</tr>
|
|
703
829
|
<tr>
|
|
@@ -814,15 +940,9 @@ Common functions for setup, movement, manipulation and math shared by both.
|
|
|
814
940
|
|
|
815
941
|
## Async
|
|
816
942
|
|
|
817
|
-
With 4.0 you can now use ``BiReaderAsync`` and ``BiWriterAsync`` for async operations. Pass a normal Buffer
|
|
818
|
-
|
|
819
|
-
**Naming:** Same function naming applies to async as [Common Functions](#common-functions) section but this class is all async functions. ``BiReader`` and ``BiWriter`` are interchangeable when it comes to all functions and class objects names but get and set methods are now also async functions.
|
|
820
|
-
|
|
821
|
-
**Writing:** When operating a file, **all write functions will throw an error unless you switch to `.writeMode(true)`**. The file is read only in ``BiReaderAsync`` until you do (``BiWriterAsync`` is true). Any write functions inside the reader size will error beforehand.
|
|
822
|
-
|
|
823
|
-
**Large removal:** When using any function that removes data from the file and would return a Buffer, **if the size of the returned Buffer is outside of the Node max size for a Buffer, a new file will be made with the location and size concat to the name with a .removed file extention instead.**
|
|
943
|
+
With 4.0 you can now use ``BiReaderAsync`` and ``BiWriterAsync`` for async operations. Pass a normal Buffer, Uint8Array or a string path (only in Node.js). When passed a Buffer or Uint8Array, it's uses the same logic as the sync class. When working with reading or creating a file, the class async loads the files in chunks for quick editing (window size is editing). This class is designed for larger files where you don't want to load the whole file buffer into memory all at once or need an async class.
|
|
824
944
|
|
|
825
|
-
**
|
|
945
|
+
**Naming:** Same function naming applies to async as [Common Functions](#common-functions) section but these classes use all async functions, **so `get` and `set` methods are now also async functions.**
|
|
826
946
|
|
|
827
947
|
<table>
|
|
828
948
|
<thead>
|
|
@@ -835,117 +955,21 @@ With 4.0 you can now use ``BiReaderAsync`` and ``BiWriterAsync`` for async opera
|
|
|
835
955
|
<tbody>
|
|
836
956
|
<tr>
|
|
837
957
|
<td>Class</td>
|
|
838
|
-
<td>new BiReaderAsync(<b>dataOrFilePath</b>, {byteOffset, bitOffset, endianess, strict,
|
|
839
|
-
<td
|
|
958
|
+
<td>new BiReaderAsync(<b>dataOrFilePath</b>, {byteOffset, bitOffset, endianess, strict, growthIncrement, readOnly, windowSize})</td>
|
|
959
|
+
<td rowspan="2"><b>dataOrPath:</b> string path or Buffer or Uint8Array</b><br><b>byteOffset:</b> byte offset (default <code>0</code>)<br><b>bitOffset:</b> bit offset (overides <code>byteOffset</code>) (default <code>0</code>)<br><b>endianess:</b> endian big or little (default <code>little</code>)<br><b>strict:</b> strict mode restrict extending initially supplied data (default <code>true</code> for reader, <code>false</code> for writer)<br><b>growthIncrement:</b> default extended Buffer size (default <code>1 MiB</code>)<br><b>enforceBigInt:</b> always return <code>bigint</code> values on 64 bit reads (default <code>false</code>)<br><b>readOnly:</b> read only Buffer or file (default <code>true</code> in writer)<br><b>windowSize:</b> The chunk size when reading files. Set to <code>0</code> if you want the whole file read in one async cycle (default <code>4 KiB</code>)
|
|
840
960
|
</td>
|
|
841
|
-
<td rowspan="2">Start with new Constructor.<br><br><b>Note:</b> The file must be opened with
|
|
961
|
+
<td rowspan="2">Start with new Constructor.<br><br><b>Note:</b> The file must be opened with await <code>.open()</code> and closed with await <code>.close()</code>. The <b>.data</b> can't be used in file mode, so use await <code>.get()</code> or <code>.return()</code></td>
|
|
842
962
|
</tr>
|
|
843
963
|
<tr>
|
|
844
964
|
<td>Class</td>
|
|
845
|
-
<td>new BiWriterAsync(<b>dataOrFilePath</b>, {byteOffset, bitOffset, endianess, strict,
|
|
846
|
-
</tr>
|
|
847
|
-
<th align="center" colspan="4"><i>File Control</i></th>
|
|
848
|
-
<tr>
|
|
849
|
-
<td>Async</td>
|
|
850
|
-
<td>open()
|
|
851
|
-
<td align="center"><b>none</td>
|
|
852
|
-
<td>Opens file for reading / writing.</td>
|
|
853
|
-
</tr>
|
|
854
|
-
<tr>
|
|
855
|
-
<td>Async</td>
|
|
856
|
-
<td>close()
|
|
857
|
-
<td align="center"><b>none</td>
|
|
858
|
-
<td>Closes file after reading / writing.</td>
|
|
859
|
-
</tr>
|
|
860
|
-
<tr>
|
|
861
|
-
<td>Async</td>
|
|
862
|
-
<td>create(<b>dataOrFilePath</b>, {byteOffset, bitOffset, endianess, strict, extendBufferSize, writeable})</td>
|
|
863
|
-
<td align="center"><b>Path to file or Buffer or Uint8Array</b>, byte offset (default 0), bit offset (default 0), endian big or little (default little), strict mode true to restrict extending file size (default true for reader, false for writer), extended file size amount, edit the file (default true in BiWriterAsync).</td>
|
|
864
|
-
<td>Creates a new class and opens the file.</td>
|
|
965
|
+
<td>new BiWriterAsync(<b>dataOrFilePath</b>, {byteOffset, bitOffset, endianess, strict, growthIncrement, readOnly, windowSize})</td>
|
|
865
966
|
</tr>
|
|
967
|
+
<th align="center" colspan="4"><i>Quick Create</i></th>
|
|
866
968
|
<tr>
|
|
867
969
|
<td>Function</td>
|
|
868
|
-
<td>
|
|
869
|
-
<td
|
|
870
|
-
<td>
|
|
871
|
-
</tr>
|
|
872
|
-
<tr>
|
|
873
|
-
<td>Async</td>
|
|
874
|
-
<td>renameFile(<b>newFilePath</b>)
|
|
875
|
-
<td align="center"><b>Full path to file to rename.</td>
|
|
876
|
-
<td>Renames the file on the file system, keeps read / write position.<br/><br/><b>Note: This is permanent.</b></td>
|
|
877
|
-
</tr>
|
|
878
|
-
<tr>
|
|
879
|
-
<td>Async</td>
|
|
880
|
-
<td>deleteFile()
|
|
881
|
-
<td align="center"><b>none</td>
|
|
882
|
-
<td>Unlinks the file from the file system.<br/><br/><b>Note: This is permanent, it doesn't send the file to the recycling bin for recovery.</b></td>
|
|
883
|
-
</tr>
|
|
884
|
-
</tbody>
|
|
885
|
-
</table>
|
|
886
|
-
|
|
887
|
-
## BiLegacy
|
|
888
|
-
|
|
889
|
-
With 4.0 you can now use ``BiReaderLegacy`` and ``BiWriterLegacy`` (old ``BiStreamReader`` and ``BiStreamWriter``) for older versions of Node.js only. It's designed for larger files where you can't or don't want to load the whole file buffer into memory all at once.
|
|
890
|
-
|
|
891
|
-
**Naming:** Same function naming applies to legacy as [Common Functions](#common-functions) section but this class saves the file after every operation. **BiReaderLegacy / BiReader** and **BiWriterLegacy / BiWriter** are interchangeable when it comes to all functions and class objects names for easy use with Typescript.
|
|
892
|
-
|
|
893
|
-
**Writing:** Unlike the other classes, **all write functions will throw an error unless you switch to `.writeMode(true)`** The file is read only until you do. Any write functions inside the reader will error beforehand.
|
|
894
|
-
|
|
895
|
-
**Large removal:** When using any function that removes data from the file and would return a Buffer, **if the size of the returned Buffer is outside of the Node max size for a Buffer, a new file will be made with the location and size concat to the name with a .removed file extention instead.**
|
|
896
|
-
|
|
897
|
-
**Programmers Note:** These are *NOT* async function (use [Async](#async) classes for that) or streamed over time like ``fs.createReadStream``. It uses ``fs.openSync`` and ``fs.readSync`` and ``fs.writeSync`` to read and write just the data requested at the position requested at the time of operation, saving memory but costing processing power. This is for legacy systems and niche cases as the newer versions of Node.js have a much larger file buffers over the older limits.
|
|
898
|
-
|
|
899
|
-
<table>
|
|
900
|
-
<thead>
|
|
901
|
-
<tr>
|
|
902
|
-
<th align="center" colspan="2">Methods</th>
|
|
903
|
-
<th align="center">Params (bold requires)</th>
|
|
904
|
-
<th align="left">Desc</th>
|
|
905
|
-
</tr>
|
|
906
|
-
</thead>
|
|
907
|
-
<tbody>
|
|
908
|
-
<tr>
|
|
909
|
-
<td>Class</td>
|
|
910
|
-
<td>new BiReaderLegacy(<b>filePath</b>, {byteOffset, bitOffset, endianess, strict, extendBufferSize, writeable})</td>
|
|
911
|
-
<td align="center" rowspan="2"><b>Path to file</b>, byte offset (default 0), bit offset (default 0), endian big or little (default little), strict mode true to restrict extending file size (default true for reader, false for writer), extended file size amount, edit the file (default true in BiWriterLegacy).
|
|
912
|
-
</td>
|
|
913
|
-
<td rowspan="2">Start with new Constructor.<br><br><b>Note:</b> The file must be opened with <b>.open()</b> and closed with <b>.close()</b>. The <b>.data</b> value is always the Buffer to the last read or write value. Read sizes outside of Node's max size will error, unless remove then it will create a new file.<br><br><b>Writer note:</b> You can set the <b>extendBufferSize</b> value to always extend the file by this minimum amount when reaching the end of the file. The file is saved after every write.</td>
|
|
914
|
-
</tr>
|
|
915
|
-
<tr>
|
|
916
|
-
<td>Class</td>
|
|
917
|
-
<td>new BiWriterLegacy(<b>filePath</b>, {byteOffset, bitOffset, endianess, strict, extendBufferSize, writeable})</td>
|
|
918
|
-
</tr>
|
|
919
|
-
<th align="center" colspan="4"><i>File Control</i></th>
|
|
920
|
-
<tr>
|
|
921
|
-
<td>Function</td>
|
|
922
|
-
<td>open()
|
|
923
|
-
<td align="center"><b>none</td>
|
|
924
|
-
<td>Opens file for reading / writing.</td>
|
|
925
|
-
</tr>
|
|
926
|
-
<tr>
|
|
927
|
-
<td>Function</td>
|
|
928
|
-
<td>close()
|
|
929
|
-
<td align="center"><b>none</td>
|
|
930
|
-
<td>Closes file after reading / writing.</td>
|
|
931
|
-
</tr>
|
|
932
|
-
<tr>
|
|
933
|
-
<td>Function</td>
|
|
934
|
-
<td>writeMode(writable)
|
|
935
|
-
<td align="center"><b>True if you want to switch to writing in BiReaderLegacy.</td>
|
|
936
|
-
<td>Note: This changes reader to write mode. Allows file to be expanded in size as well.</td>
|
|
937
|
-
</tr>
|
|
938
|
-
<tr>
|
|
939
|
-
<td>Function</td>
|
|
940
|
-
<td>renameFile(<b>newFilePath</b>)
|
|
941
|
-
<td align="center"><b>Full path to file to rename.</td>
|
|
942
|
-
<td>Renames the file on the file system, keeps read / write position.<br/><br/><b>Note: This is permanent.</b></td>
|
|
943
|
-
</tr>
|
|
944
|
-
<tr>
|
|
945
|
-
<td>Function</td>
|
|
946
|
-
<td>deleteFile()
|
|
947
|
-
<td align="center"><b>none</td>
|
|
948
|
-
<td>Unlinks the file from the file system.<br/><br/><b>Note: This is permanent, it doesn't send the file to the recycling bin for recovery.</b></td>
|
|
970
|
+
<td>create(<b>dataOrFilePath</b>, {byteOffset, bitOffset, endianess, strict, growthIncrement, readOnly, windowSize})
|
|
971
|
+
<td>Same as above</tb>
|
|
972
|
+
<td>Static async function that creates and opens the class all at once.</td>
|
|
949
973
|
</tr>
|
|
950
974
|
</tbody>
|
|
951
975
|
</table>
|
|
@@ -1234,7 +1258,7 @@ Parse value as a double float (aka dfloat). Can be in little or big endian order
|
|
|
1234
1258
|
|
|
1235
1259
|
## Strings
|
|
1236
1260
|
|
|
1237
|
-
Parse a string in any format. Be sure to use options object for formatting unless using a preset. Strings with larger than 1 byte character reads can use `be` or `le` at the end for little or big endian.
|
|
1261
|
+
Parse a string in any format. Either null terminated strings (utf) or fixed length (pascal). Be sure to use options object for formatting unless using a preset. Default string settings can be stored in `strSettings`. Strings with larger than 1 byte character reads can use `be` or `le` at the end for little or big endian.
|
|
1238
1262
|
|
|
1239
1263
|
Presents include C or Unicode, Ansi and multiple pascals.
|
|
1240
1264
|
|
|
@@ -1260,7 +1284,7 @@ Presents include C or Unicode, Ansi and multiple pascals.
|
|
|
1260
1284
|
endian<br>
|
|
1261
1285
|
})
|
|
1262
1286
|
</td>
|
|
1263
|
-
<td><
|
|
1287
|
+
<td><b>length:</b> Length in uints (NOT bytes) for non-terminate UTF strings. If not supplied, reads until <code>0x00</code> or supplied terminate value (for fixed length UTF strings only)<br><b>stringType:</b> String type. Defaults to utf-8 (<code>utf-8</code>, <code>utf-16</code>, <code>utf-32</code>, <code>pascal</code>, <code>wide-pascal</code>, <code>double-wide-pascal</code> accepted)<br><b>terminateValue:</b> Terminate value. Default is <code>0x00</code> (for non-fixed length utf strings)<br><b>lengthReadSize:</b> Size of the first value that defines the length of the string. Defaults to <code>1</code> as uint8, respects supplied endian (for Pascal strings only, accepts <code>1</code>, <code>2</code> or <code>4</code> bytes)<br><b>stripNull:</b> Removes 0x00 characters on read (default <code>true</code>)<br><b>encoding:</b> Defaults to <code>utf-8</code> (accepts all TextDecoder options)<br><b>endian:</b> for <code>utf-16</code>, <code>utf-32</code>, <code>wide-pascal</code> and <code>double-wide-pascal</code> character order</td>
|
|
1264
1288
|
</tr>
|
|
1265
1289
|
<tr>
|
|
1266
1290
|
<td>writeString(<b>string</b>, {<br>
|
|
@@ -1271,33 +1295,91 @@ Presents include C or Unicode, Ansi and multiple pascals.
|
|
|
1271
1295
|
encoding,<br>
|
|
1272
1296
|
endian<br>
|
|
1273
1297
|
})</td>
|
|
1274
|
-
<td
|
|
1298
|
+
<td>
|
|
1299
|
+
<b>string:</b> String to write<br>
|
|
1300
|
+
length:</b> Length in uints (NOT bytes) for non-terminate UTF strings. If not supplied, reads until <code>0x00</code> or supplied terminate value (for fixed length UTF strings only, in units NOT bytes)<br>
|
|
1301
|
+
<b>stringType:</b> String type. Defaults to utf-8 (<code>utf-8</code>, <code>utf-16</code>, <code>utf-32</code>, <code>pascal</code>, <code>wide-pascal</code>, <code>double-wide-pascal</code> accepted)<br>
|
|
1302
|
+
<b>terminateValue:</b> Terminate value. Default is <code>0x00</code> (for non-fixed length utf strings)<br>
|
|
1303
|
+
<b>lengthReadSize:</b> Size of the first value that defines the length of the string. Defaults to <code>1</code> as uint8, respects supplied endian (for Pascal strings only, accepts <code>1</code>, <code>2</code> or <code>4</code> bytes)<br>
|
|
1304
|
+
<b>encoding:</b> Defaults to <code>utf-8</code> (accepts all TextDecoder options)<br>
|
|
1305
|
+
<b>endian:</b> for <code>utf-16</code>, <code>utf-32</code>, <code>wide-pascal</code> and <code>double-wide-pascal</code> character order</td>
|
|
1275
1306
|
</tr>
|
|
1276
1307
|
<tr>
|
|
1277
|
-
<td
|
|
1308
|
+
<td><b>Default settings</b></td>
|
|
1309
|
+
<td>strSettings = {length?, stringType?, terminateValue?, lengthReadSize?, lengthWriteSize?, stripNull?, encoding?, endian?}</td>
|
|
1310
|
+
<td>
|
|
1311
|
+
<b>length:</b> Length of string for fixed length, non-terminate value utf strings (in units NOT bytes)<br/>
|
|
1312
|
+
<b>stringType:</b> <code>utf-8</code>, <code>utf-16</code>, <code>utf-32</code>,<code>pascal</code>, <code>wide-pascal</code> or <code>double-wide-pascal</code>. Default <code>utf-8</code>.<br/>
|
|
1313
|
+
<b>terminateValue:</b> Number only with <code>stringType</code> of utf types.<br/>
|
|
1314
|
+
<b>lengthReadSize</b> For pascal strings. 1, 2 or 4 byte length read size. Default <code>1</code><br/>
|
|
1315
|
+
<b>lengthWriteSize:</b> For pascal strings. 1, 2 or 4 byte length write size. Default <code>1</code>.<br/>
|
|
1316
|
+
<b>stripNull:</b> Removes code>0x00</code> characters. default <code>true</code><br/>
|
|
1317
|
+
<b>encoding:</b> TextEncoder accepted types. Default <code>utf-8</code>.<br/>
|
|
1318
|
+
<b>endian:</b> <code>big</code> or <code>little</code><br/>
|
|
1319
|
+
</td>
|
|
1320
|
+
</tr>
|
|
1321
|
+
<tr>
|
|
1322
|
+
<td><b>get / set</b></td>
|
|
1323
|
+
<td>str()</td>
|
|
1324
|
+
<td>
|
|
1325
|
+
Quickly read or write a string with the set <code>strSettings</code> options.
|
|
1326
|
+
</td>
|
|
1327
|
+
</tr>
|
|
1328
|
+
<tr>
|
|
1329
|
+
<td align="center"><b>Functions (reader)</b></td>
|
|
1330
|
+
<td>
|
|
1331
|
+
{c|utf8}string(length, terminateValue, stripNull)<br>
|
|
1332
|
+
ansistring(length, terminateValue, stripNull)<br>
|
|
1333
|
+
pstring(lengthReadSize, stripNull, endian)<br>
|
|
1334
|
+
pstring{1|2|4}{be|le}(stripNull, endian)
|
|
1335
|
+
</td>
|
|
1336
|
+
<td>Get a single byte string as a fixed length (pascal) or null terminated (utf) string</td>
|
|
1337
|
+
</tr>
|
|
1338
|
+
<tr>
|
|
1339
|
+
<td align="center"><b>Functions (reader)</b></td>
|
|
1340
|
+
<td>
|
|
1341
|
+
{utf16|uni}string(length, terminateValue, stripNull, endian)<br>
|
|
1342
|
+
wpstring{be|le}(lengthReadSize, stripNull, endian)<br>
|
|
1343
|
+
wpstring{1|2|4}{be|le}(stripNull, endian)
|
|
1344
|
+
</td>
|
|
1345
|
+
<td>Get a wide (2 byte) string as a fixed length (pascal) or null terminated (utf) string</td>
|
|
1346
|
+
</tr>
|
|
1347
|
+
<tr>
|
|
1348
|
+
<td align="center"><b>Functions (reader)</b></td>
|
|
1349
|
+
<td>
|
|
1350
|
+
utf32string{be|le}(length, terminateValue, stripNull, endian)<br>
|
|
1351
|
+
dwpstring{be|le}(lengthReadSize, stripNull, endian)<br>
|
|
1352
|
+
dwpstring{1|2|4}{be|le}(stripNull, endian)
|
|
1353
|
+
</td>
|
|
1354
|
+
<td>Get a double wide (4 byte) string as a fixed length (pascal) or null terminated (utf) string</td></td>
|
|
1355
|
+
</tr>
|
|
1356
|
+
<tr>
|
|
1357
|
+
<td align="center"><b>Functions (writer)</b></td>
|
|
1358
|
+
<td>
|
|
1359
|
+
{c|utf8}string(<b>string</b>, length, terminateValue)<br>
|
|
1360
|
+
ansistring(<b>string</b>, length, terminateValue)<br>
|
|
1361
|
+
pstring(<b>string</b>, lengthWriteSize, endian)<br>
|
|
1362
|
+
pstring{1|2|4}{be|le}(<b>string</b>, endian)
|
|
1363
|
+
</td>
|
|
1364
|
+
<td>Write a single byte string as a fixed length (pascal) or null terminated (utf) string</td>
|
|
1365
|
+
</tr>
|
|
1366
|
+
<tr>
|
|
1367
|
+
<td align="center"><b>Functions (writer)</b></td>
|
|
1278
1368
|
<td>
|
|
1279
|
-
{
|
|
1280
|
-
|
|
1281
|
-
{
|
|
1282
|
-
pstring(lengthReadSize, stripNull, *endian)<br><br>
|
|
1283
|
-
pstring{1|2|4}{be|le}(stripNull, *endian)<br><br>
|
|
1284
|
-
wpstring{be|le}(lengthReadSize, stripNull, *endian)<br><br>
|
|
1285
|
-
wpstring{1|2|4}{be|le}(stripNull, *endian)
|
|
1369
|
+
{utf16|uni}string{be|le}(<b>string</b>,length, terminateValue, endian)<br>
|
|
1370
|
+
wpstring{be|le}(<b>string</b>, lengthWriteSize, endian)<br>
|
|
1371
|
+
wpstring{1|2|4}{be|le}(<b>string</b>, endian)
|
|
1286
1372
|
</td>
|
|
1287
|
-
<td>
|
|
1373
|
+
<td>Write a wide (2 byte) string as a fixed length (pascal) or null terminated (utf) string</td>
|
|
1288
1374
|
</tr>
|
|
1289
1375
|
<tr>
|
|
1290
|
-
|
|
1376
|
+
<td align="center"><b>Functions (writer)</b></td>
|
|
1291
1377
|
<td>
|
|
1292
|
-
{
|
|
1293
|
-
|
|
1294
|
-
{
|
|
1295
|
-
pstring(<b>string</b>, lengthWriteSize, *endian)<br><br>
|
|
1296
|
-
pstring{1|2|4}{be|le}(<b>string</b>, *endian)<br><br>
|
|
1297
|
-
wpstring{be|le}(<b>string</b>, lengthWriteSize, *endian)<br><br>
|
|
1298
|
-
wpstring{1|2|4}{be|le}(<b>string</b>, *endian)
|
|
1378
|
+
utf32string{be|le}(<b>string</b>,length, terminateValue, endian)<br>
|
|
1379
|
+
dwpstring{be|le}(<b>string</b>, lengthWriteSize, endian)<br>
|
|
1380
|
+
dwpstring{1|2|4}{be|le}(<b>string</b>, endian)
|
|
1299
1381
|
</td>
|
|
1300
|
-
<td>
|
|
1382
|
+
<td>Write a double wide (4 byte) string as a fixed length (pascal) or null terminated (utf) string</td></td>
|
|
1301
1383
|
</tr>
|
|
1302
1384
|
</tbody>
|
|
1303
1385
|
</table>
|