bireader 3.1.1 → 3.1.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 CHANGED
@@ -793,7 +793,7 @@ With 3.1 you can now use ``BiReaderStream`` and ``BiWriterStream`` in Node for l
793
793
 
794
794
  ### Streaming Caveats
795
795
 
796
- * Naming: Same naming applies to streamers as [Common Functions](#common-functions) section but the file is saved after every operation.
796
+ * Naming: Same function naming applies to streamers as [Common Functions](#common-functions) section but the file is saved after every operation. **BiReaderStream / BiReader** and **BiWriterStream / BiWriter** are interchangeable when it comes to all functions and class objects names for easy use with type script.
797
797
  * Writing: Unlike the other BiReader, **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.
798
798
  * 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.**
799
799
 
@@ -1,46 +1,5 @@
1
1
  /// <reference types="node" />
2
2
  import { endian, hexdumpOptions, stringOptions } from '../common.js';
3
- export declare function hexDumpBase(ctx: BiBase, options?: hexdumpOptions): string;
4
- export declare function skip(ctx: BiBase, bytes: number, bits?: number): void;
5
- export declare function align(ctx: BiBase, n: number): void;
6
- export declare function alignRev(ctx: BiBase, n: number): void;
7
- export declare function goto(ctx: BiBase, bytes: number, bits?: number): void;
8
- export declare function check_size(ctx: BiBase, write_bytes: number, write_bit?: number, offset?: number): number;
9
- export declare function checkSize(ctx: BiBase, write_bytes: number, write_bit?: number, offset?: number): number;
10
- export declare function extendarray(ctx: BiBase, to_padd: number): void;
11
- export declare function remove(ctx: BiBase, startOffset?: number, endOffset?: number, consume?: boolean, remove?: boolean, fillValue?: number): any;
12
- export declare function addData(ctx: BiBase, data: Buffer | Uint8Array, consume?: boolean, offset?: number, replace?: boolean): void;
13
- export declare function AND(ctx: BiBase, and_key: any, start?: number, end?: number, consume?: boolean): any;
14
- export declare function OR(ctx: BiBase, or_key: any, start?: number, end?: number, consume?: boolean): any;
15
- export declare function XOR(ctx: BiBase, xor_key: any, start?: number, end?: number, consume?: boolean): any;
16
- export declare function NOT(ctx: BiBase, start?: number, end?: number, consume?: boolean): any;
17
- export declare function LSHIFT(ctx: BiBase, shift_key: any, start?: number, end?: number, consume?: boolean): any;
18
- export declare function RSHIFT(ctx: BiBase, shift_key: any, start?: number, end?: number, consume?: boolean): any;
19
- export declare function ADD(ctx: BiBase, add_key: any, start?: number, end?: number, consume?: boolean): any;
20
- export declare function fString(ctx: BiBase, searchString: string): number;
21
- export declare function fNumber(ctx: BiBase, targetNumber: number, bits: number, unsigned: boolean, endian?: string): number;
22
- export declare function fHalfFloat(ctx: BiBase, targetNumber: number, endian?: string): number;
23
- export declare function fFloat(ctx: BiBase, targetNumber: number, endian?: string): number;
24
- export declare function fBigInt(ctx: BiBase, targetNumber: number, unsigned: boolean, endian?: string): number;
25
- export declare function fDoubleFloat(ctx: BiBase, targetNumber: number, endian?: string): number;
26
- export declare function wbit(ctx: BiBase, value: number, bits: number, unsigned?: boolean, endian?: string): void;
27
- export declare function rbit(ctx: BiBase, bits?: number, unsigned?: boolean, endian?: string): number;
28
- export declare function wbyte(ctx: BiBase, value: number, unsigned?: boolean): void;
29
- export declare function rbyte(ctx: BiBase, unsigned?: boolean): number;
30
- export declare function wint16(ctx: BiBase, value: number, unsigned?: boolean, endian?: string): void;
31
- export declare function rint16(ctx: BiBase, unsigned?: boolean, endian?: string): number;
32
- export declare function rhalffloat(ctx: BiBase, endian?: endian): number;
33
- export declare function whalffloat(ctx: BiBase, value: number, endian?: string): void;
34
- export declare function wint32(ctx: BiBase, value: number, unsigned?: boolean, endian?: string): void;
35
- export declare function rint32(ctx: BiBase, unsigned?: boolean, endian?: string): number;
36
- export declare function rfloat(ctx: BiBase, endian?: endian): number;
37
- export declare function wfloat(ctx: BiBase, value: number, endian?: string): void;
38
- export declare function rint64(ctx: BiBase, unsigned?: boolean, endian?: string): bigint;
39
- export declare function wint64(ctx: BiBase, value: number, unsigned?: boolean, endian?: string): void;
40
- export declare function wdfloat(ctx: BiBase, value: number, endian?: string): void;
41
- export declare function rdfloat(ctx: BiBase, endian?: endian): number;
42
- export declare function rstring(ctx: BiBase, options?: stringOptions): string;
43
- export declare function wstring(ctx: BiBase, string: string, options?: stringOptions): void;
44
3
  export declare class BiBase {
45
4
  /**
46
5
  * Endianness of default read.
@@ -73,9 +32,9 @@ export declare class BiBase {
73
32
  errorDump: boolean;
74
33
  /**
75
34
  * Current buffer data.
76
- * @type {Buffer|Uint8Array}
35
+ * @type {Buffer|Uint8Array|null}
77
36
  */
78
- data: any;
37
+ data: Buffer | Uint8Array | null;
79
38
  /**
80
39
  * When the data buffer needs to be extended while strict mode is ``false``, this will be the amount it extends.
81
40
  *
@@ -86,18 +45,53 @@ export declare class BiBase {
86
45
  * NOTE: Using ``BiWriter.get`` or ``BiWriter.return`` will now remove all data after the current write position. Use ``BiWriter.data`` to get the full buffer instead.
87
46
  */
88
47
  extendBufferSize: number;
48
+ fd: any;
49
+ filePath: string;
50
+ fsMode: string;
89
51
  /**
90
52
  * The settings that used when using the .str getter / setter
91
53
  */
92
54
  private strDefaults;
55
+ maxFileSize: number | null;
56
+ constructor();
93
57
  /**
94
58
  * Settings for when using .str
95
59
  *
96
60
  * @param {stringOptions} settings options to use with .str
97
61
  */
98
62
  set strSettings(settings: stringOptions);
99
- isBufferOrUint8Array(obj: Buffer | Uint8Array): boolean;
63
+ /**
64
+ * Enables expanding in reader (changes strict)
65
+ *
66
+ * @param {boolean} mode - Enable expanding in reader (changes strict)
67
+ */
68
+ writeMode(mode: boolean): void;
69
+ /**
70
+ * Dummy function, not needed on Non-Stream
71
+ */
72
+ open(): number;
73
+ /**
74
+ * Dummy function, not needed on Non-Stream
75
+ */
76
+ updateSize(): void;
77
+ /**
78
+ * removes data.
79
+ */
80
+ close(): void;
81
+ /**
82
+ * Dummy function, not needed on Non-Stream
83
+ */
84
+ read(start: number, length: number, consume?: boolean): Buffer | Uint8Array;
85
+ /**
86
+ * Dummy function, not needed on Non-Stream
87
+ */
88
+ write(start: number, data: Buffer, consume?: boolean): number;
89
+ /**
90
+ * Dummy function, not needed on Non-Stream
91
+ */
92
+ commit(consume?: boolean): number;
100
93
  extendArray(to_padd: number): void;
94
+ isBufferOrUint8Array(obj: Buffer | Uint8Array): boolean;
101
95
  /**
102
96
  *
103
97
  * Change endian, defaults to little.
@@ -338,10 +332,6 @@ export declare class BiBase {
338
332
  * removes data.
339
333
  */
340
334
  end(): void;
341
- /**
342
- * removes data.
343
- */
344
- close(): void;
345
335
  /**
346
336
  * removes data.
347
337
  */
@@ -42,7 +42,7 @@ export declare class BiBaseStreamer {
42
42
  /**
43
43
  * Current buffer chunk.
44
44
  *
45
- * @type {Buffer}
45
+ * @type {Buffer|null}
46
46
  */
47
47
  data: Buffer | null;
48
48
  /**
@@ -336,15 +336,15 @@ export declare class BiBaseStreamer {
336
336
  */
337
337
  get return(): Buffer;
338
338
  /**
339
- * Creates hex dump string. Will console log or return string if set in options.
340
- *
341
- * @param {object} options
342
- * @param {hexdumpOptions?} options - hex dump options
343
- * @param {number?} options.length - number of bytes to log, default ``192`` or end of data
344
- * @param {number?} options.startByte - byte to start dump (default ``0``)
345
- * @param {boolean?} options.supressUnicode - Supress unicode character preview for even columns.
346
- * @param {boolean?} options.returnString - Returns the hex dump string instead of logging it.
347
- */
339
+ * Creates hex dump string. Will console log or return string if set in options.
340
+ *
341
+ * @param {object} options
342
+ * @param {hexdumpOptions?} options - hex dump options
343
+ * @param {number?} options.length - number of bytes to log, default ``192`` or end of data
344
+ * @param {number?} options.startByte - byte to start dump (default ``0``)
345
+ * @param {boolean?} options.supressUnicode - Supress unicode character preview for even columns.
346
+ * @param {boolean?} options.returnString - Returns the hex dump string instead of logging it.
347
+ */
348
348
  hexdump(options?: hexdumpOptions): void | string;
349
349
  /**
350
350
  * Turn hexdump on error off (default on).
@@ -118,9 +118,9 @@ declare class BiBase {
118
118
  errorDump: boolean;
119
119
  /**
120
120
  * Current buffer data.
121
- * @type {Buffer|Uint8Array}
121
+ * @type {Buffer|Uint8Array|null}
122
122
  */
123
- data: any;
123
+ data: Buffer | Uint8Array | null;
124
124
  /**
125
125
  * When the data buffer needs to be extended while strict mode is ``false``, this will be the amount it extends.
126
126
  *
@@ -131,18 +131,53 @@ declare class BiBase {
131
131
  * NOTE: Using ``BiWriter.get`` or ``BiWriter.return`` will now remove all data after the current write position. Use ``BiWriter.data`` to get the full buffer instead.
132
132
  */
133
133
  extendBufferSize: number;
134
+ fd: any;
135
+ filePath: string;
136
+ fsMode: string;
134
137
  /**
135
138
  * The settings that used when using the .str getter / setter
136
139
  */
137
140
  private strDefaults;
141
+ maxFileSize: number | null;
142
+ constructor();
138
143
  /**
139
144
  * Settings for when using .str
140
145
  *
141
146
  * @param {stringOptions} settings options to use with .str
142
147
  */
143
148
  set strSettings(settings: stringOptions);
144
- isBufferOrUint8Array(obj: Buffer | Uint8Array): boolean;
149
+ /**
150
+ * Enables expanding in reader (changes strict)
151
+ *
152
+ * @param {boolean} mode - Enable expanding in reader (changes strict)
153
+ */
154
+ writeMode(mode: boolean): void;
155
+ /**
156
+ * Dummy function, not needed on Non-Stream
157
+ */
158
+ open(): number;
159
+ /**
160
+ * Dummy function, not needed on Non-Stream
161
+ */
162
+ updateSize(): void;
163
+ /**
164
+ * removes data.
165
+ */
166
+ close(): void;
167
+ /**
168
+ * Dummy function, not needed on Non-Stream
169
+ */
170
+ read(start: number, length: number, consume?: boolean): Buffer | Uint8Array;
171
+ /**
172
+ * Dummy function, not needed on Non-Stream
173
+ */
174
+ write(start: number, data: Buffer, consume?: boolean): number;
175
+ /**
176
+ * Dummy function, not needed on Non-Stream
177
+ */
178
+ commit(consume?: boolean): number;
145
179
  extendArray(to_padd: number): void;
180
+ isBufferOrUint8Array(obj: Buffer | Uint8Array): boolean;
146
181
  /**
147
182
  *
148
183
  * Change endian, defaults to little.
@@ -383,10 +418,6 @@ declare class BiBase {
383
418
  * removes data.
384
419
  */
385
420
  end(): void;
386
- /**
387
- * removes data.
388
- */
389
- close(): void;
390
421
  /**
391
422
  * removes data.
392
423
  */
@@ -1727,9 +1727,9 @@ class BiBase {
1727
1727
  this.errorDump = true;
1728
1728
  /**
1729
1729
  * Current buffer data.
1730
- * @type {Buffer|Uint8Array}
1730
+ * @type {Buffer|Uint8Array|null}
1731
1731
  */
1732
- this.data = [];
1732
+ this.data = null;
1733
1733
  /**
1734
1734
  * When the data buffer needs to be extended while strict mode is ``false``, this will be the amount it extends.
1735
1735
  *
@@ -1740,10 +1740,14 @@ class BiBase {
1740
1740
  * NOTE: Using ``BiWriter.get`` or ``BiWriter.return`` will now remove all data after the current write position. Use ``BiWriter.data`` to get the full buffer instead.
1741
1741
  */
1742
1742
  this.extendBufferSize = 0;
1743
+ this.fd = null;
1744
+ this.filePath = "";
1745
+ this.fsMode = "";
1743
1746
  /**
1744
1747
  * The settings that used when using the .str getter / setter
1745
1748
  */
1746
1749
  this.strDefaults = { stringType: "utf-8", terminateValue: 0x0 };
1750
+ this.maxFileSize = null;
1747
1751
  }
1748
1752
  /**
1749
1753
  * Settings for when using .str
@@ -1760,12 +1764,67 @@ class BiBase {
1760
1764
  this.strDefaults.stripNull = settings.stripNull;
1761
1765
  this.strDefaults.terminateValue = settings.terminateValue;
1762
1766
  }
1763
- isBufferOrUint8Array(obj) {
1764
- return arraybuffcheck(obj);
1767
+ /**
1768
+ * Enables expanding in reader (changes strict)
1769
+ *
1770
+ * @param {boolean} mode - Enable expanding in reader (changes strict)
1771
+ */
1772
+ writeMode(mode) {
1773
+ if (mode) {
1774
+ this.strict = false;
1775
+ return;
1776
+ }
1777
+ else {
1778
+ this.strict = true;
1779
+ return;
1780
+ }
1781
+ }
1782
+ /**
1783
+ * Dummy function, not needed on Non-Stream
1784
+ */
1785
+ open() {
1786
+ return this.size;
1787
+ }
1788
+ /**
1789
+ * Dummy function, not needed on Non-Stream
1790
+ */
1791
+ updateSize() {
1792
+ this.return;
1793
+ }
1794
+ /**
1795
+ * removes data.
1796
+ */
1797
+ close() {
1798
+ this.data = undefined;
1799
+ }
1800
+ /**
1801
+ * Dummy function, not needed on Non-Stream
1802
+ */
1803
+ read(start, length, consume = false) {
1804
+ return this.lift(start, start + length, consume);
1805
+ }
1806
+ /**
1807
+ * Dummy function, not needed on Non-Stream
1808
+ */
1809
+ write(start, data, consume = false) {
1810
+ this.insert(data, consume, start);
1811
+ return data.length;
1812
+ }
1813
+ /**
1814
+ * Dummy function, not needed on Non-Stream
1815
+ */
1816
+ commit(consume = true) {
1817
+ return consume ? 0 : 1;
1765
1818
  }
1766
1819
  extendArray(to_padd) {
1767
1820
  return extendarray(this, to_padd);
1768
1821
  }
1822
+ isBufferOrUint8Array(obj) {
1823
+ return arraybuffcheck(obj);
1824
+ }
1825
+ ///////////////////////////////
1826
+ // ENDIANNESS //
1827
+ ///////////////////////////////
1769
1828
  /**
1770
1829
  *
1771
1830
  * Change endian, defaults to little.
@@ -1819,6 +1878,9 @@ class BiBase {
1819
1878
  le() {
1820
1879
  this.endianness("little");
1821
1880
  }
1881
+ ///////////////////////////////
1882
+ // SIZE //
1883
+ ///////////////////////////////
1822
1884
  /**
1823
1885
  * Size in bytes of the current buffer.
1824
1886
  *
@@ -1867,9 +1929,9 @@ class BiBase {
1867
1929
  get lenb() {
1868
1930
  return this.sizeB;
1869
1931
  }
1870
- //
1871
- //get position
1872
- //
1932
+ ///////////////////////////////
1933
+ // POSITION //
1934
+ ///////////////////////////////
1873
1935
  /**
1874
1936
  * Get the current byte position.
1875
1937
  *
@@ -2030,9 +2092,9 @@ class BiBase {
2030
2092
  get row() {
2031
2093
  return Math.abs(Math.floor((this.offset - 1) / 16));
2032
2094
  }
2033
- //
2034
- //finishing
2035
- //
2095
+ ///////////////////////////////
2096
+ // FINISHING //
2097
+ ///////////////////////////////
2036
2098
  /**
2037
2099
  * Returns current data.
2038
2100
  *
@@ -2088,9 +2150,9 @@ class BiBase {
2088
2150
  errorDumpOn() {
2089
2151
  this.errorDump = true;
2090
2152
  }
2091
- //
2092
- //strict mode change
2093
- //
2153
+ ///////////////////////////////
2154
+ // STRICTMODE //
2155
+ ///////////////////////////////
2094
2156
  /**
2095
2157
  * Disallows extending data if position is outside of max size.
2096
2158
  */
@@ -2109,12 +2171,6 @@ class BiBase {
2109
2171
  end() {
2110
2172
  this.data = undefined;
2111
2173
  }
2112
- /**
2113
- * removes data.
2114
- */
2115
- close() {
2116
- this.data = undefined;
2117
- }
2118
2174
  /**
2119
2175
  * removes data.
2120
2176
  */
@@ -2127,9 +2183,9 @@ class BiBase {
2127
2183
  finished() {
2128
2184
  this.data = undefined;
2129
2185
  }
2130
- //
2131
- //find
2132
- //
2186
+ ///////////////////////////////
2187
+ // FIND //
2188
+ ///////////////////////////////
2133
2189
  /**
2134
2190
  * Searches for byte position of string from current read position.
2135
2191
  *
@@ -2237,9 +2293,9 @@ class BiBase {
2237
2293
  findDoubleFloat(value, endian) {
2238
2294
  return fDoubleFloat(this, value, endian);
2239
2295
  }
2240
- //
2241
- // move from current position
2242
- //
2296
+ ///////////////////////////////
2297
+ // MOVE TO //
2298
+ ///////////////////////////////
2243
2299
  /**
2244
2300
  * Aligns current byte position.
2245
2301
  *
@@ -2260,9 +2316,6 @@ class BiBase {
2260
2316
  alignRev(number) {
2261
2317
  return alignRev(this, number);
2262
2318
  }
2263
- //
2264
- // directly set current position
2265
- //
2266
2319
  /**
2267
2320
  * Offset current byte or bit position.
2268
2321
  *
@@ -2340,9 +2393,6 @@ class BiBase {
2340
2393
  warp(byte, bit) {
2341
2394
  return this.goto(byte, bit);
2342
2395
  }
2343
- //
2344
- // go to start
2345
- //
2346
2396
  /**
2347
2397
  * Set byte and bit position to start of data.
2348
2398
  */
@@ -2377,9 +2427,9 @@ class BiBase {
2377
2427
  this.offset = this.size;
2378
2428
  this.bitoffset = 0;
2379
2429
  }
2380
- //
2381
- //remove part of data
2382
- //
2430
+ ///////////////////////////////
2431
+ // REMOVE //
2432
+ ///////////////////////////////
2383
2433
  /**
2384
2434
  * Deletes part of data from start to current byte position unless supplied, returns removed.
2385
2435
  *
@@ -2461,9 +2511,9 @@ class BiBase {
2461
2511
  overwrite(data, consume, offset) {
2462
2512
  return addData(this, data, consume || false, offset || this.offset, true);
2463
2513
  }
2464
- //
2465
- // copy out
2466
- //
2514
+ ///////////////////////////////
2515
+ // COPY OUT //
2516
+ ///////////////////////////////
2467
2517
  /**
2468
2518
  * Returns part of data from current byte position to end of data unless supplied.
2469
2519
  *
@@ -2524,9 +2574,9 @@ class BiBase {
2524
2574
  wrap(length, consume) {
2525
2575
  return remove(this, this.offset, this.offset + (length || 0), consume || false, false);
2526
2576
  }
2527
- //
2528
- //insert
2529
- //
2577
+ ///////////////////////////////
2578
+ // INSERT //
2579
+ ///////////////////////////////
2530
2580
  /**
2531
2581
  * Inserts data into data.
2532
2582
  *
@@ -2595,9 +2645,9 @@ class BiBase {
2595
2645
  append(data, consume) {
2596
2646
  return addData(this, data, consume || false, this.size, false);
2597
2647
  }
2598
- //
2599
- // math
2600
- //
2648
+ ///////////////////////////////
2649
+ // MATH //
2650
+ ///////////////////////////////
2601
2651
  /**
2602
2652
  * XOR data.
2603
2653
  *
@@ -2893,9 +2943,9 @@ class BiBase {
2893
2943
  }
2894
2944
  return RSHIFT(this, lShiftKey, this.offset, this.offset + Length, consume || false);
2895
2945
  }
2896
- //
2897
- //bit reader
2898
- //
2946
+ ///////////////////////////////
2947
+ // BIT READER //
2948
+ ///////////////////////////////
2899
2949
  /**
2900
2950
  *
2901
2951
  * Write bits, must have at least value and number of bits.