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 +1 -1
- package/dist/core/BiBase.d.ts +38 -48
- package/dist/core/BiBaseStream.d.ts +10 -10
- package/dist/index.browser.d.ts +38 -7
- package/dist/index.browser.js +96 -46
- package/dist/index.browser.js.map +1 -1
- package/dist/index.cjs.d.ts +48 -17
- package/dist/index.cjs.js +142 -109
- package/dist/index.cjs.js.map +1 -1
- package/dist/index.d.ts +48 -17
- package/dist/index.esm.d.ts +48 -17
- package/dist/index.esm.js +142 -109
- package/dist/index.esm.js.map +1 -1
- package/package.json +1 -1
- package/tsconfig.json +0 -15
package/dist/index.esm.js
CHANGED
|
@@ -1730,9 +1730,9 @@ class BiBase {
|
|
|
1730
1730
|
this.errorDump = true;
|
|
1731
1731
|
/**
|
|
1732
1732
|
* Current buffer data.
|
|
1733
|
-
* @type {Buffer|Uint8Array}
|
|
1733
|
+
* @type {Buffer|Uint8Array|null}
|
|
1734
1734
|
*/
|
|
1735
|
-
this.data =
|
|
1735
|
+
this.data = null;
|
|
1736
1736
|
/**
|
|
1737
1737
|
* When the data buffer needs to be extended while strict mode is ``false``, this will be the amount it extends.
|
|
1738
1738
|
*
|
|
@@ -1743,10 +1743,14 @@ class BiBase {
|
|
|
1743
1743
|
* 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.
|
|
1744
1744
|
*/
|
|
1745
1745
|
this.extendBufferSize = 0;
|
|
1746
|
+
this.fd = null;
|
|
1747
|
+
this.filePath = "";
|
|
1748
|
+
this.fsMode = "";
|
|
1746
1749
|
/**
|
|
1747
1750
|
* The settings that used when using the .str getter / setter
|
|
1748
1751
|
*/
|
|
1749
1752
|
this.strDefaults = { stringType: "utf-8", terminateValue: 0x0 };
|
|
1753
|
+
this.maxFileSize = null;
|
|
1750
1754
|
}
|
|
1751
1755
|
/**
|
|
1752
1756
|
* Settings for when using .str
|
|
@@ -1763,12 +1767,67 @@ class BiBase {
|
|
|
1763
1767
|
this.strDefaults.stripNull = settings.stripNull;
|
|
1764
1768
|
this.strDefaults.terminateValue = settings.terminateValue;
|
|
1765
1769
|
}
|
|
1766
|
-
|
|
1767
|
-
|
|
1770
|
+
/**
|
|
1771
|
+
* Enables expanding in reader (changes strict)
|
|
1772
|
+
*
|
|
1773
|
+
* @param {boolean} mode - Enable expanding in reader (changes strict)
|
|
1774
|
+
*/
|
|
1775
|
+
writeMode(mode) {
|
|
1776
|
+
if (mode) {
|
|
1777
|
+
this.strict = false;
|
|
1778
|
+
return;
|
|
1779
|
+
}
|
|
1780
|
+
else {
|
|
1781
|
+
this.strict = true;
|
|
1782
|
+
return;
|
|
1783
|
+
}
|
|
1784
|
+
}
|
|
1785
|
+
/**
|
|
1786
|
+
* Dummy function, not needed on Non-Stream
|
|
1787
|
+
*/
|
|
1788
|
+
open() {
|
|
1789
|
+
return this.size;
|
|
1790
|
+
}
|
|
1791
|
+
/**
|
|
1792
|
+
* Dummy function, not needed on Non-Stream
|
|
1793
|
+
*/
|
|
1794
|
+
updateSize() {
|
|
1795
|
+
this.return;
|
|
1796
|
+
}
|
|
1797
|
+
/**
|
|
1798
|
+
* removes data.
|
|
1799
|
+
*/
|
|
1800
|
+
close() {
|
|
1801
|
+
this.data = undefined;
|
|
1802
|
+
}
|
|
1803
|
+
/**
|
|
1804
|
+
* Dummy function, not needed on Non-Stream
|
|
1805
|
+
*/
|
|
1806
|
+
read(start, length, consume = false) {
|
|
1807
|
+
return this.lift(start, start + length, consume);
|
|
1808
|
+
}
|
|
1809
|
+
/**
|
|
1810
|
+
* Dummy function, not needed on Non-Stream
|
|
1811
|
+
*/
|
|
1812
|
+
write(start, data, consume = false) {
|
|
1813
|
+
this.insert(data, consume, start);
|
|
1814
|
+
return data.length;
|
|
1815
|
+
}
|
|
1816
|
+
/**
|
|
1817
|
+
* Dummy function, not needed on Non-Stream
|
|
1818
|
+
*/
|
|
1819
|
+
commit(consume = true) {
|
|
1820
|
+
return consume ? 0 : 1;
|
|
1768
1821
|
}
|
|
1769
1822
|
extendArray(to_padd) {
|
|
1770
1823
|
return extendarray(this, to_padd);
|
|
1771
1824
|
}
|
|
1825
|
+
isBufferOrUint8Array(obj) {
|
|
1826
|
+
return arraybuffcheck(obj);
|
|
1827
|
+
}
|
|
1828
|
+
///////////////////////////////
|
|
1829
|
+
// ENDIANNESS //
|
|
1830
|
+
///////////////////////////////
|
|
1772
1831
|
/**
|
|
1773
1832
|
*
|
|
1774
1833
|
* Change endian, defaults to little.
|
|
@@ -1822,6 +1881,9 @@ class BiBase {
|
|
|
1822
1881
|
le() {
|
|
1823
1882
|
this.endianness("little");
|
|
1824
1883
|
}
|
|
1884
|
+
///////////////////////////////
|
|
1885
|
+
// SIZE //
|
|
1886
|
+
///////////////////////////////
|
|
1825
1887
|
/**
|
|
1826
1888
|
* Size in bytes of the current buffer.
|
|
1827
1889
|
*
|
|
@@ -1870,9 +1932,9 @@ class BiBase {
|
|
|
1870
1932
|
get lenb() {
|
|
1871
1933
|
return this.sizeB;
|
|
1872
1934
|
}
|
|
1873
|
-
|
|
1874
|
-
//
|
|
1875
|
-
|
|
1935
|
+
///////////////////////////////
|
|
1936
|
+
// POSITION //
|
|
1937
|
+
///////////////////////////////
|
|
1876
1938
|
/**
|
|
1877
1939
|
* Get the current byte position.
|
|
1878
1940
|
*
|
|
@@ -2033,9 +2095,9 @@ class BiBase {
|
|
|
2033
2095
|
get row() {
|
|
2034
2096
|
return Math.abs(Math.floor((this.offset - 1) / 16));
|
|
2035
2097
|
}
|
|
2036
|
-
|
|
2037
|
-
//
|
|
2038
|
-
|
|
2098
|
+
///////////////////////////////
|
|
2099
|
+
// FINISHING //
|
|
2100
|
+
///////////////////////////////
|
|
2039
2101
|
/**
|
|
2040
2102
|
* Returns current data.
|
|
2041
2103
|
*
|
|
@@ -2091,9 +2153,9 @@ class BiBase {
|
|
|
2091
2153
|
errorDumpOn() {
|
|
2092
2154
|
this.errorDump = true;
|
|
2093
2155
|
}
|
|
2094
|
-
|
|
2095
|
-
//
|
|
2096
|
-
|
|
2156
|
+
///////////////////////////////
|
|
2157
|
+
// STRICTMODE //
|
|
2158
|
+
///////////////////////////////
|
|
2097
2159
|
/**
|
|
2098
2160
|
* Disallows extending data if position is outside of max size.
|
|
2099
2161
|
*/
|
|
@@ -2112,12 +2174,6 @@ class BiBase {
|
|
|
2112
2174
|
end() {
|
|
2113
2175
|
this.data = undefined;
|
|
2114
2176
|
}
|
|
2115
|
-
/**
|
|
2116
|
-
* removes data.
|
|
2117
|
-
*/
|
|
2118
|
-
close() {
|
|
2119
|
-
this.data = undefined;
|
|
2120
|
-
}
|
|
2121
2177
|
/**
|
|
2122
2178
|
* removes data.
|
|
2123
2179
|
*/
|
|
@@ -2130,9 +2186,9 @@ class BiBase {
|
|
|
2130
2186
|
finished() {
|
|
2131
2187
|
this.data = undefined;
|
|
2132
2188
|
}
|
|
2133
|
-
|
|
2134
|
-
//
|
|
2135
|
-
|
|
2189
|
+
///////////////////////////////
|
|
2190
|
+
// FIND //
|
|
2191
|
+
///////////////////////////////
|
|
2136
2192
|
/**
|
|
2137
2193
|
* Searches for byte position of string from current read position.
|
|
2138
2194
|
*
|
|
@@ -2240,9 +2296,9 @@ class BiBase {
|
|
|
2240
2296
|
findDoubleFloat(value, endian) {
|
|
2241
2297
|
return fDoubleFloat$1(this, value, endian);
|
|
2242
2298
|
}
|
|
2243
|
-
|
|
2244
|
-
//
|
|
2245
|
-
|
|
2299
|
+
///////////////////////////////
|
|
2300
|
+
// MOVE TO //
|
|
2301
|
+
///////////////////////////////
|
|
2246
2302
|
/**
|
|
2247
2303
|
* Aligns current byte position.
|
|
2248
2304
|
*
|
|
@@ -2263,9 +2319,6 @@ class BiBase {
|
|
|
2263
2319
|
alignRev(number) {
|
|
2264
2320
|
return alignRev$1(this, number);
|
|
2265
2321
|
}
|
|
2266
|
-
//
|
|
2267
|
-
// directly set current position
|
|
2268
|
-
//
|
|
2269
2322
|
/**
|
|
2270
2323
|
* Offset current byte or bit position.
|
|
2271
2324
|
*
|
|
@@ -2343,9 +2396,6 @@ class BiBase {
|
|
|
2343
2396
|
warp(byte, bit) {
|
|
2344
2397
|
return this.goto(byte, bit);
|
|
2345
2398
|
}
|
|
2346
|
-
//
|
|
2347
|
-
// go to start
|
|
2348
|
-
//
|
|
2349
2399
|
/**
|
|
2350
2400
|
* Set byte and bit position to start of data.
|
|
2351
2401
|
*/
|
|
@@ -2380,9 +2430,9 @@ class BiBase {
|
|
|
2380
2430
|
this.offset = this.size;
|
|
2381
2431
|
this.bitoffset = 0;
|
|
2382
2432
|
}
|
|
2383
|
-
|
|
2384
|
-
//
|
|
2385
|
-
|
|
2433
|
+
///////////////////////////////
|
|
2434
|
+
// REMOVE //
|
|
2435
|
+
///////////////////////////////
|
|
2386
2436
|
/**
|
|
2387
2437
|
* Deletes part of data from start to current byte position unless supplied, returns removed.
|
|
2388
2438
|
*
|
|
@@ -2464,9 +2514,9 @@ class BiBase {
|
|
|
2464
2514
|
overwrite(data, consume, offset) {
|
|
2465
2515
|
return addData$1(this, data, consume || false, offset || this.offset, true);
|
|
2466
2516
|
}
|
|
2467
|
-
|
|
2468
|
-
//
|
|
2469
|
-
|
|
2517
|
+
///////////////////////////////
|
|
2518
|
+
// COPY OUT //
|
|
2519
|
+
///////////////////////////////
|
|
2470
2520
|
/**
|
|
2471
2521
|
* Returns part of data from current byte position to end of data unless supplied.
|
|
2472
2522
|
*
|
|
@@ -2527,9 +2577,9 @@ class BiBase {
|
|
|
2527
2577
|
wrap(length, consume) {
|
|
2528
2578
|
return remove$1(this, this.offset, this.offset + (length || 0), consume || false, false);
|
|
2529
2579
|
}
|
|
2530
|
-
|
|
2531
|
-
//
|
|
2532
|
-
|
|
2580
|
+
///////////////////////////////
|
|
2581
|
+
// INSERT //
|
|
2582
|
+
///////////////////////////////
|
|
2533
2583
|
/**
|
|
2534
2584
|
* Inserts data into data.
|
|
2535
2585
|
*
|
|
@@ -2598,9 +2648,9 @@ class BiBase {
|
|
|
2598
2648
|
append(data, consume) {
|
|
2599
2649
|
return addData$1(this, data, consume || false, this.size, false);
|
|
2600
2650
|
}
|
|
2601
|
-
|
|
2602
|
-
//
|
|
2603
|
-
|
|
2651
|
+
///////////////////////////////
|
|
2652
|
+
// MATH //
|
|
2653
|
+
///////////////////////////////
|
|
2604
2654
|
/**
|
|
2605
2655
|
* XOR data.
|
|
2606
2656
|
*
|
|
@@ -2896,9 +2946,9 @@ class BiBase {
|
|
|
2896
2946
|
}
|
|
2897
2947
|
return RSHIFT$1(this, lShiftKey, this.offset, this.offset + Length, consume || false);
|
|
2898
2948
|
}
|
|
2899
|
-
|
|
2900
|
-
//
|
|
2901
|
-
|
|
2949
|
+
///////////////////////////////
|
|
2950
|
+
// BIT READER //
|
|
2951
|
+
///////////////////////////////
|
|
2902
2952
|
/**
|
|
2903
2953
|
*
|
|
2904
2954
|
* Write bits, must have at least value and number of bits.
|
|
@@ -13314,7 +13364,7 @@ class BiBaseStreamer {
|
|
|
13314
13364
|
/**
|
|
13315
13365
|
* Current buffer chunk.
|
|
13316
13366
|
*
|
|
13317
|
-
* @type {Buffer}
|
|
13367
|
+
* @type {Buffer|null}
|
|
13318
13368
|
*/
|
|
13319
13369
|
this.data = null;
|
|
13320
13370
|
/**
|
|
@@ -13556,28 +13606,14 @@ class BiBaseStreamer {
|
|
|
13556
13606
|
}
|
|
13557
13607
|
}
|
|
13558
13608
|
fs.ftruncateSync(this.fd, this.size + length);
|
|
13559
|
-
//if (this.maxFileSize && this.maxFileSize > length) {
|
|
13560
|
-
// // stream extend
|
|
13561
|
-
// const CHUNK_SIZE = 64 * 1024;
|
|
13562
|
-
// const buffer = Buffer.alloc(CHUNK_SIZE);
|
|
13563
|
-
// var amount = length;
|
|
13564
|
-
// var start = this.size;
|
|
13565
|
-
// while (amount) {
|
|
13566
|
-
// const toWrite = Math.min(CHUNK_SIZE, amount);
|
|
13567
|
-
// fs.writeSync(this.fd, buffer, 0, toWrite, start);
|
|
13568
|
-
// start += toWrite;
|
|
13569
|
-
// amount -= toWrite;
|
|
13570
|
-
// }
|
|
13571
|
-
//}
|
|
13572
|
-
//else {
|
|
13573
|
-
// const buffer = Buffer.alloc(length);
|
|
13574
|
-
// fs.writeSync(this.fd, buffer, 0, buffer.length, this.size);
|
|
13575
|
-
//}
|
|
13576
13609
|
this.updateSize();
|
|
13577
13610
|
}
|
|
13578
13611
|
isBufferOrUint8Array(obj) {
|
|
13579
13612
|
return arraybuffcheck(obj);
|
|
13580
13613
|
}
|
|
13614
|
+
///////////////////////////////
|
|
13615
|
+
// ENDIANNESS //
|
|
13616
|
+
///////////////////////////////
|
|
13581
13617
|
/**
|
|
13582
13618
|
*
|
|
13583
13619
|
* Change endian, defaults to little.
|
|
@@ -13631,6 +13667,9 @@ class BiBaseStreamer {
|
|
|
13631
13667
|
le() {
|
|
13632
13668
|
this.endianness("little");
|
|
13633
13669
|
}
|
|
13670
|
+
///////////////////////////////
|
|
13671
|
+
// SIZE //
|
|
13672
|
+
///////////////////////////////
|
|
13634
13673
|
/**
|
|
13635
13674
|
* Size in bytes of the current buffer.
|
|
13636
13675
|
*
|
|
@@ -13679,9 +13718,9 @@ class BiBaseStreamer {
|
|
|
13679
13718
|
get lenb() {
|
|
13680
13719
|
return this.sizeB;
|
|
13681
13720
|
}
|
|
13682
|
-
|
|
13683
|
-
//
|
|
13684
|
-
|
|
13721
|
+
///////////////////////////////
|
|
13722
|
+
// POSITION //
|
|
13723
|
+
///////////////////////////////
|
|
13685
13724
|
/**
|
|
13686
13725
|
* Get the current byte position.
|
|
13687
13726
|
*
|
|
@@ -13842,9 +13881,9 @@ class BiBaseStreamer {
|
|
|
13842
13881
|
get row() {
|
|
13843
13882
|
return Math.abs(Math.floor((this.offset - 1) / 16));
|
|
13844
13883
|
}
|
|
13845
|
-
|
|
13846
|
-
//
|
|
13847
|
-
|
|
13884
|
+
///////////////////////////////
|
|
13885
|
+
// FINISHING //
|
|
13886
|
+
///////////////////////////////
|
|
13848
13887
|
/**
|
|
13849
13888
|
* Returns current data.
|
|
13850
13889
|
*
|
|
@@ -13876,15 +13915,15 @@ class BiBaseStreamer {
|
|
|
13876
13915
|
return this.data || Buffer.alloc(0);
|
|
13877
13916
|
}
|
|
13878
13917
|
/**
|
|
13879
|
-
|
|
13880
|
-
|
|
13881
|
-
|
|
13882
|
-
|
|
13883
|
-
|
|
13884
|
-
|
|
13885
|
-
|
|
13886
|
-
|
|
13887
|
-
|
|
13918
|
+
* Creates hex dump string. Will console log or return string if set in options.
|
|
13919
|
+
*
|
|
13920
|
+
* @param {object} options
|
|
13921
|
+
* @param {hexdumpOptions?} options - hex dump options
|
|
13922
|
+
* @param {number?} options.length - number of bytes to log, default ``192`` or end of data
|
|
13923
|
+
* @param {number?} options.startByte - byte to start dump (default ``0``)
|
|
13924
|
+
* @param {boolean?} options.supressUnicode - Supress unicode character preview for even columns.
|
|
13925
|
+
* @param {boolean?} options.returnString - Returns the hex dump string instead of logging it.
|
|
13926
|
+
*/
|
|
13888
13927
|
hexdump(options = {}) {
|
|
13889
13928
|
return hexDump(this, options);
|
|
13890
13929
|
}
|
|
@@ -13900,9 +13939,9 @@ class BiBaseStreamer {
|
|
|
13900
13939
|
errorDumpOn() {
|
|
13901
13940
|
this.errorDump = true;
|
|
13902
13941
|
}
|
|
13903
|
-
|
|
13904
|
-
//
|
|
13905
|
-
|
|
13942
|
+
///////////////////////////////
|
|
13943
|
+
// STRICTMODE //
|
|
13944
|
+
///////////////////////////////
|
|
13906
13945
|
/**
|
|
13907
13946
|
* Disallows extending data if position is outside of max size.
|
|
13908
13947
|
*/
|
|
@@ -13933,9 +13972,9 @@ class BiBaseStreamer {
|
|
|
13933
13972
|
finished() {
|
|
13934
13973
|
this.data = null;
|
|
13935
13974
|
}
|
|
13936
|
-
|
|
13937
|
-
//
|
|
13938
|
-
|
|
13975
|
+
///////////////////////////////
|
|
13976
|
+
// FIND //
|
|
13977
|
+
///////////////////////////////
|
|
13939
13978
|
/**
|
|
13940
13979
|
* Searches for byte position of string from current read position.
|
|
13941
13980
|
*
|
|
@@ -14043,9 +14082,9 @@ class BiBaseStreamer {
|
|
|
14043
14082
|
findDoubleFloat(value, endian) {
|
|
14044
14083
|
return fDoubleFloat(this, value, endian);
|
|
14045
14084
|
}
|
|
14046
|
-
|
|
14047
|
-
//
|
|
14048
|
-
|
|
14085
|
+
///////////////////////////////
|
|
14086
|
+
// MOVE TO //
|
|
14087
|
+
///////////////////////////////
|
|
14049
14088
|
/**
|
|
14050
14089
|
* Aligns current byte position.
|
|
14051
14090
|
*
|
|
@@ -14066,9 +14105,6 @@ class BiBaseStreamer {
|
|
|
14066
14105
|
alignRev(number) {
|
|
14067
14106
|
return alignRev(this, number);
|
|
14068
14107
|
}
|
|
14069
|
-
//
|
|
14070
|
-
// directly set current position
|
|
14071
|
-
//
|
|
14072
14108
|
/**
|
|
14073
14109
|
* Offset current byte or bit position.
|
|
14074
14110
|
*
|
|
@@ -14146,9 +14182,6 @@ class BiBaseStreamer {
|
|
|
14146
14182
|
warp(byte, bit) {
|
|
14147
14183
|
return this.goto(byte, bit);
|
|
14148
14184
|
}
|
|
14149
|
-
//
|
|
14150
|
-
// go to start
|
|
14151
|
-
//
|
|
14152
14185
|
/**
|
|
14153
14186
|
* Set byte and bit position to start of data.
|
|
14154
14187
|
*/
|
|
@@ -14183,9 +14216,9 @@ class BiBaseStreamer {
|
|
|
14183
14216
|
this.offset = this.size;
|
|
14184
14217
|
this.bitoffset = 0;
|
|
14185
14218
|
}
|
|
14186
|
-
|
|
14187
|
-
//
|
|
14188
|
-
|
|
14219
|
+
///////////////////////////////
|
|
14220
|
+
// REMOVE //
|
|
14221
|
+
///////////////////////////////
|
|
14189
14222
|
/**
|
|
14190
14223
|
* Deletes part of data from start to current byte position unless supplied, returns removed.
|
|
14191
14224
|
*
|
|
@@ -14267,9 +14300,9 @@ class BiBaseStreamer {
|
|
|
14267
14300
|
overwrite(data, consume, offset) {
|
|
14268
14301
|
return addData(this, data, consume || false, offset || this.offset, true);
|
|
14269
14302
|
}
|
|
14270
|
-
|
|
14271
|
-
//
|
|
14272
|
-
|
|
14303
|
+
///////////////////////////////
|
|
14304
|
+
// COPY OUT //
|
|
14305
|
+
///////////////////////////////
|
|
14273
14306
|
/**
|
|
14274
14307
|
* Returns part of data from current byte position to end of data unless supplied.
|
|
14275
14308
|
*
|
|
@@ -14330,9 +14363,9 @@ class BiBaseStreamer {
|
|
|
14330
14363
|
wrap(length, consume) {
|
|
14331
14364
|
return remove(this, this.offset, this.offset + (length || 0), consume || false, false);
|
|
14332
14365
|
}
|
|
14333
|
-
|
|
14334
|
-
//
|
|
14335
|
-
|
|
14366
|
+
///////////////////////////////
|
|
14367
|
+
// INSERT //
|
|
14368
|
+
///////////////////////////////
|
|
14336
14369
|
/**
|
|
14337
14370
|
* Inserts data into data.
|
|
14338
14371
|
*
|
|
@@ -14401,9 +14434,9 @@ class BiBaseStreamer {
|
|
|
14401
14434
|
append(data, consume) {
|
|
14402
14435
|
return addData(this, data, consume || false, this.size, false);
|
|
14403
14436
|
}
|
|
14404
|
-
|
|
14405
|
-
//
|
|
14406
|
-
|
|
14437
|
+
///////////////////////////////
|
|
14438
|
+
// MATH //
|
|
14439
|
+
///////////////////////////////
|
|
14407
14440
|
/**
|
|
14408
14441
|
* XOR data.
|
|
14409
14442
|
*
|
|
@@ -14699,9 +14732,9 @@ class BiBaseStreamer {
|
|
|
14699
14732
|
}
|
|
14700
14733
|
return RSHIFT(this, lShiftKey, this.offset, this.offset + Length, consume || false);
|
|
14701
14734
|
}
|
|
14702
|
-
|
|
14703
|
-
//
|
|
14704
|
-
|
|
14735
|
+
///////////////////////////////
|
|
14736
|
+
// BIT READER //
|
|
14737
|
+
///////////////////////////////
|
|
14705
14738
|
/**
|
|
14706
14739
|
*
|
|
14707
14740
|
* Write bits, must have at least value and number of bits.
|