bireader 1.0.45 → 1.0.47
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/lib/cjs/index.d.ts +36 -0
- package/lib/cjs/index.d.ts.map +1 -1
- package/lib/cjs/index.js +56 -36
- package/lib/cjs/index.js.map +1 -1
- package/lib/esm/index.d.ts +36 -0
- package/lib/esm/index.d.ts.map +1 -1
- package/lib/esm/index.js.map +1 -1
- package/lib/esm/index.mjs +56 -36
- package/package.json +1 -1
package/lib/esm/index.mjs
CHANGED
|
@@ -170,48 +170,32 @@ function addData(_this, data, consume, offset, replace) {
|
|
|
170
170
|
}
|
|
171
171
|
var needed_size = offset || _this.offset;
|
|
172
172
|
if (replace) {
|
|
173
|
-
needed_size = offset || _this.offset + data.length;
|
|
174
|
-
}
|
|
175
|
-
if (needed_size > _this.size) {
|
|
176
|
-
if (_this.strict == false) {
|
|
177
|
-
_this.extendArray(needed_size - _this.size);
|
|
178
|
-
}
|
|
179
|
-
else {
|
|
180
|
-
_this.errorDump ? "\x1b[31m[Error]\x1b[0m: hexdump:\n" + _this.hexdump() : "";
|
|
181
|
-
throw new Error("\x1b[33m[Strict mode]\x1b[0m: End offset outside of data: endOffset" + needed_size + " of " + _this.size);
|
|
182
|
-
}
|
|
183
|
-
_this.size = _this.data.length;
|
|
173
|
+
needed_size = (offset || _this.offset) + data.length;
|
|
184
174
|
}
|
|
185
175
|
if (replace) {
|
|
176
|
+
const part1 = _this.data.subarray(0, needed_size - data.length);
|
|
177
|
+
const part2 = _this.data.subarray(needed_size, _this.size);
|
|
186
178
|
if (isBuffer(_this.data)) {
|
|
187
|
-
const part1 = _this.data.subarray(0, needed_size - data.length);
|
|
188
|
-
const part2 = _this.data.subarray(needed_size, _this.size);
|
|
189
179
|
_this.data = Buffer.concat([part1, data, part2]);
|
|
190
|
-
_this.size = _this.data.length;
|
|
191
180
|
}
|
|
192
181
|
else {
|
|
193
|
-
const part1 = _this.data.subarray(0, needed_size - data.length);
|
|
194
|
-
const part2 = _this.data.subarray(needed_size, _this.size);
|
|
195
182
|
_this.data = new Uint8Array([...part1, ...data, ...part2]);
|
|
196
|
-
_this.size = _this.data.length;
|
|
197
183
|
}
|
|
184
|
+
_this.size = _this.data.length;
|
|
198
185
|
}
|
|
199
186
|
else {
|
|
187
|
+
const part1 = _this.data.subarray(0, needed_size);
|
|
188
|
+
const part2 = _this.data.subarray(needed_size, _this.size);
|
|
200
189
|
if (isBuffer(_this.data)) {
|
|
201
|
-
const part1 = _this.data.subarray(0, needed_size);
|
|
202
|
-
const part2 = _this.data.subarray(needed_size, _this.size);
|
|
203
190
|
_this.data = Buffer.concat([part1, data, part2]);
|
|
204
|
-
_this.size = _this.data.length;
|
|
205
191
|
}
|
|
206
192
|
else {
|
|
207
|
-
const part1 = _this.data.subarray(0, needed_size);
|
|
208
|
-
const part2 = _this.data.subarray(needed_size, _this.size);
|
|
209
193
|
_this.data = new Uint8Array([...part1, ...data, ...part2]);
|
|
210
|
-
_this.size = _this.data.length;
|
|
211
194
|
}
|
|
195
|
+
_this.size = _this.data.length;
|
|
212
196
|
}
|
|
213
197
|
if (consume) {
|
|
214
|
-
_this.offset =
|
|
198
|
+
_this.offset = (offset || _this.offset) + data.length;
|
|
215
199
|
_this.bitoffset = 0;
|
|
216
200
|
}
|
|
217
201
|
}
|
|
@@ -1766,6 +1750,7 @@ export class bireader {
|
|
|
1766
1750
|
}
|
|
1767
1751
|
/**
|
|
1768
1752
|
* Offset current byte or bit position
|
|
1753
|
+
*
|
|
1769
1754
|
* Note: Will extend array if strict mode is off and outside of max size
|
|
1770
1755
|
*
|
|
1771
1756
|
* @param {number} bytes - Bytes to skip
|
|
@@ -1776,6 +1761,7 @@ export class bireader {
|
|
|
1776
1761
|
}
|
|
1777
1762
|
/**
|
|
1778
1763
|
* Offset current byte or bit position
|
|
1764
|
+
*
|
|
1779
1765
|
* Note: Will extend array if strict mode is off and outside of max size
|
|
1780
1766
|
*
|
|
1781
1767
|
* @param {number} bytes - Bytes to skip
|
|
@@ -1789,6 +1775,7 @@ export class bireader {
|
|
|
1789
1775
|
//
|
|
1790
1776
|
/**
|
|
1791
1777
|
* Change position directly to address
|
|
1778
|
+
*
|
|
1792
1779
|
* Note: Will extend array if strict mode is off and outside of max size
|
|
1793
1780
|
*
|
|
1794
1781
|
* @param {number} byte - byte to set to
|
|
@@ -1799,6 +1786,7 @@ export class bireader {
|
|
|
1799
1786
|
}
|
|
1800
1787
|
/**
|
|
1801
1788
|
* Offset current byte or bit position
|
|
1789
|
+
*
|
|
1802
1790
|
* Note: Will extend array if strict mode is off and outside of max size
|
|
1803
1791
|
*
|
|
1804
1792
|
* @param {number} bytes - Bytes to skip
|
|
@@ -1809,6 +1797,7 @@ export class bireader {
|
|
|
1809
1797
|
}
|
|
1810
1798
|
/**
|
|
1811
1799
|
* Change position directly to address
|
|
1800
|
+
*
|
|
1812
1801
|
* Note: Will extend array if strict mode is off and outside of max size
|
|
1813
1802
|
*
|
|
1814
1803
|
* @param {number} byte - byte to set to
|
|
@@ -1819,6 +1808,7 @@ export class bireader {
|
|
|
1819
1808
|
}
|
|
1820
1809
|
/**
|
|
1821
1810
|
* Change position directly to address
|
|
1811
|
+
*
|
|
1822
1812
|
* Note: Will extend array if strict mode is off and outside of max size
|
|
1823
1813
|
*
|
|
1824
1814
|
* @param {number} byte - byte to set to
|
|
@@ -2260,6 +2250,7 @@ export class bireader {
|
|
|
2260
2250
|
//
|
|
2261
2251
|
/**
|
|
2262
2252
|
* Deletes part of data from start to current byte position unless supplied, returns removed
|
|
2253
|
+
*
|
|
2263
2254
|
* Note: Errors in strict mode
|
|
2264
2255
|
*
|
|
2265
2256
|
* @param {number} startOffset - Start location (default 0)
|
|
@@ -2272,6 +2263,7 @@ export class bireader {
|
|
|
2272
2263
|
}
|
|
2273
2264
|
/**
|
|
2274
2265
|
* Deletes part of data from current byte position to end, returns removed
|
|
2266
|
+
*
|
|
2275
2267
|
* Note: Errors in strict mode
|
|
2276
2268
|
*
|
|
2277
2269
|
* @returns {Buffer|Uint8Array} Removed data as ``Buffer`` or ``Uint8Array``
|
|
@@ -2281,6 +2273,7 @@ export class bireader {
|
|
|
2281
2273
|
}
|
|
2282
2274
|
/**
|
|
2283
2275
|
* Deletes part of data from current byte position to end, returns removed
|
|
2276
|
+
*
|
|
2284
2277
|
* Note: Errors in strict mode
|
|
2285
2278
|
*
|
|
2286
2279
|
* @returns {Buffer|Uint8Array} Removed data as ``Buffer`` or ``Uint8Array``
|
|
@@ -2290,6 +2283,7 @@ export class bireader {
|
|
|
2290
2283
|
}
|
|
2291
2284
|
/**
|
|
2292
2285
|
* Deletes part of data from current byte position to supplied length, returns removed
|
|
2286
|
+
*
|
|
2293
2287
|
* Note: Errors in strict mode
|
|
2294
2288
|
*
|
|
2295
2289
|
* @param {number} length - Length of data in bytes to remove
|
|
@@ -2339,6 +2333,7 @@ export class bireader {
|
|
|
2339
2333
|
}
|
|
2340
2334
|
/**
|
|
2341
2335
|
* Extract data from current position to length supplied
|
|
2336
|
+
*
|
|
2342
2337
|
* Note: Does not affect supplied data
|
|
2343
2338
|
*
|
|
2344
2339
|
* @param {number} length - Length of data in bytes to copy from current offset
|
|
@@ -2350,6 +2345,7 @@ export class bireader {
|
|
|
2350
2345
|
}
|
|
2351
2346
|
/**
|
|
2352
2347
|
* Extract data from current position to length supplied
|
|
2348
|
+
*
|
|
2353
2349
|
* Note: Does not affect supplied data
|
|
2354
2350
|
*
|
|
2355
2351
|
* @param {number} length - Length of data in bytes to copy from current offset
|
|
@@ -2361,6 +2357,7 @@ export class bireader {
|
|
|
2361
2357
|
}
|
|
2362
2358
|
/**
|
|
2363
2359
|
* Extract data from current position to length supplied
|
|
2360
|
+
*
|
|
2364
2361
|
* Note: Does not affect supplied data
|
|
2365
2362
|
*
|
|
2366
2363
|
* @param {number} length - Length of data in bytes to copy from current offset
|
|
@@ -2375,6 +2372,7 @@ export class bireader {
|
|
|
2375
2372
|
//
|
|
2376
2373
|
/**
|
|
2377
2374
|
* Inserts data into data
|
|
2375
|
+
*
|
|
2378
2376
|
* Note: Must be same data type as supplied data. Errors on strict mode.
|
|
2379
2377
|
*
|
|
2380
2378
|
* @param {Buffer|Uint8Array} data - ``Uint8Array`` or ``Buffer`` to add to data
|
|
@@ -2382,10 +2380,11 @@ export class bireader {
|
|
|
2382
2380
|
* @param {number} offset - Byte position to add at (defaults to current position)
|
|
2383
2381
|
*/
|
|
2384
2382
|
insert(data, consume, offset) {
|
|
2385
|
-
return addData(this, data, consume || false, offset || this.offset);
|
|
2383
|
+
return addData(this, data, consume || false, offset || this.offset, false);
|
|
2386
2384
|
}
|
|
2387
2385
|
/**
|
|
2388
2386
|
* Inserts data into data
|
|
2387
|
+
*
|
|
2389
2388
|
* Note: Must be same data type as supplied data. Errors on strict mode.
|
|
2390
2389
|
*
|
|
2391
2390
|
* @param {Buffer|Uint8Array} data - ``Uint8Array`` or ``Buffer`` to add to data
|
|
@@ -2393,10 +2392,11 @@ export class bireader {
|
|
|
2393
2392
|
* @param {number} offset - Byte position to add at (defaults to current position)
|
|
2394
2393
|
*/
|
|
2395
2394
|
place(data, consume, offset) {
|
|
2396
|
-
return addData(this, data, consume || false, offset || this.offset);
|
|
2395
|
+
return addData(this, data, consume || false, offset || this.offset, false);
|
|
2397
2396
|
}
|
|
2398
2397
|
/**
|
|
2399
2398
|
* Replaces data in data
|
|
2399
|
+
*
|
|
2400
2400
|
* Note: Must be same data type as supplied data. Errors on strict mode.
|
|
2401
2401
|
*
|
|
2402
2402
|
* @param {Buffer|Uint8Array} data - ``Uint8Array`` or ``Buffer`` to replace in data
|
|
@@ -2408,6 +2408,7 @@ export class bireader {
|
|
|
2408
2408
|
}
|
|
2409
2409
|
/**
|
|
2410
2410
|
* Replaces data in data
|
|
2411
|
+
*
|
|
2411
2412
|
* Note: Must be same data type as supplied data. Errors on strict mode.
|
|
2412
2413
|
*
|
|
2413
2414
|
* @param {Buffer|Uint8Array} data - ``Uint8Array`` or ``Buffer`` to replace in data
|
|
@@ -2419,43 +2420,47 @@ export class bireader {
|
|
|
2419
2420
|
}
|
|
2420
2421
|
/**
|
|
2421
2422
|
* Adds data to start of supplied data
|
|
2423
|
+
*
|
|
2422
2424
|
* Note: Must be same data type as supplied data. Errors on strict mode.
|
|
2423
2425
|
*
|
|
2424
2426
|
* @param {Buffer|Uint8Array} data - ``Uint8Array`` or ``Buffer`` to add to data
|
|
2425
2427
|
* @param {boolean} consume - Move current write position to end of data (default false)
|
|
2426
2428
|
*/
|
|
2427
2429
|
unshift(data, consume) {
|
|
2428
|
-
return addData(this, data, consume || false, 0);
|
|
2430
|
+
return addData(this, data, consume || false, 0, false);
|
|
2429
2431
|
}
|
|
2430
2432
|
/**
|
|
2431
2433
|
* Adds data to start of supplied data
|
|
2434
|
+
*
|
|
2432
2435
|
* Note: Must be same data type as supplied data. Errors on strict mode.
|
|
2433
2436
|
*
|
|
2434
2437
|
* @param {Buffer|Uint8Array} data - ``Uint8Array`` or ``Buffer`` to add to data
|
|
2435
2438
|
* @param {boolean} consume - Move current write position to end of data (default false)
|
|
2436
2439
|
*/
|
|
2437
2440
|
prepend(data, consume) {
|
|
2438
|
-
return addData(this, data, consume || false, 0);
|
|
2441
|
+
return addData(this, data, consume || false, 0, false);
|
|
2439
2442
|
}
|
|
2440
2443
|
/**
|
|
2441
2444
|
* Adds data to end of supplied data
|
|
2445
|
+
*
|
|
2442
2446
|
* Note: Must be same data type as supplied data. Errors on strict mode.
|
|
2443
2447
|
*
|
|
2444
2448
|
* @param {Buffer|Uint8Array} data - ``Uint8Array`` or ``Buffer`` to add to data
|
|
2445
2449
|
* @param {boolean} consume - Move current write position to end of data (default false)
|
|
2446
2450
|
*/
|
|
2447
2451
|
push(data, consume) {
|
|
2448
|
-
return addData(this, data, consume || false, this.size);
|
|
2452
|
+
return addData(this, data, consume || false, this.size, false);
|
|
2449
2453
|
}
|
|
2450
2454
|
/**
|
|
2451
2455
|
* Adds data to end of supplied data
|
|
2456
|
+
*
|
|
2452
2457
|
* Note: Must be same data type as supplied data. Errors on strict mode.
|
|
2453
2458
|
*
|
|
2454
2459
|
* @param {Buffer|Uint8Array} data - ``Uint8Array`` or ``Buffer`` to add to data
|
|
2455
2460
|
* @param {boolean} consume - Move current write position to end of data (default false)
|
|
2456
2461
|
*/
|
|
2457
2462
|
append(data, consume) {
|
|
2458
|
-
return addData(this, data, consume || false, this.size);
|
|
2463
|
+
return addData(this, data, consume || false, this.size, false);
|
|
2459
2464
|
}
|
|
2460
2465
|
//
|
|
2461
2466
|
//finishing
|
|
@@ -6845,6 +6850,7 @@ export class biwriter {
|
|
|
6845
6850
|
//
|
|
6846
6851
|
/**
|
|
6847
6852
|
* Deletes part of data from start to current byte position unless supplied, returns removed
|
|
6853
|
+
*
|
|
6848
6854
|
* Note: Errors in strict mode
|
|
6849
6855
|
*
|
|
6850
6856
|
* @param {number} startOffset - Start location (default 0)
|
|
@@ -6857,6 +6863,7 @@ export class biwriter {
|
|
|
6857
6863
|
}
|
|
6858
6864
|
/**
|
|
6859
6865
|
* Deletes part of data from current byte position to end, returns removed
|
|
6866
|
+
*
|
|
6860
6867
|
* Note: Errors in strict mode
|
|
6861
6868
|
*
|
|
6862
6869
|
* @returns {Buffer|Uint8Array} Removed data as ``Buffer`` or ``Uint8Array``
|
|
@@ -6875,6 +6882,7 @@ export class biwriter {
|
|
|
6875
6882
|
}
|
|
6876
6883
|
/**
|
|
6877
6884
|
* Deletes part of data from current byte position to supplied length, returns removed
|
|
6885
|
+
*
|
|
6878
6886
|
* Note: Errors in strict mode
|
|
6879
6887
|
*
|
|
6880
6888
|
* @param {number} length - Length of data in bytes to remove
|
|
@@ -6886,6 +6894,7 @@ export class biwriter {
|
|
|
6886
6894
|
}
|
|
6887
6895
|
/**
|
|
6888
6896
|
* Deletes part of data from current position to supplied length, returns removed
|
|
6897
|
+
*
|
|
6889
6898
|
* Note: Only works in strict mode
|
|
6890
6899
|
*
|
|
6891
6900
|
* @param {number} length - Length of data in bytes to remove
|
|
@@ -6924,6 +6933,7 @@ export class biwriter {
|
|
|
6924
6933
|
}
|
|
6925
6934
|
/**
|
|
6926
6935
|
* Extract data from current position to length supplied
|
|
6936
|
+
*
|
|
6927
6937
|
* Note: Does not affect supplied data
|
|
6928
6938
|
*
|
|
6929
6939
|
* @param {number} length - Length of data in bytes to copy from current offset
|
|
@@ -6935,6 +6945,7 @@ export class biwriter {
|
|
|
6935
6945
|
}
|
|
6936
6946
|
/**
|
|
6937
6947
|
* Extract data from current position to length supplied
|
|
6948
|
+
*
|
|
6938
6949
|
* Note: Does not affect supplied data
|
|
6939
6950
|
*
|
|
6940
6951
|
* @param {number} length - Length of data in bytes to copy from current offset
|
|
@@ -6946,6 +6957,7 @@ export class biwriter {
|
|
|
6946
6957
|
}
|
|
6947
6958
|
/**
|
|
6948
6959
|
* Extract data from current position to length supplied
|
|
6960
|
+
*
|
|
6949
6961
|
* Note: Does not affect supplied data
|
|
6950
6962
|
*
|
|
6951
6963
|
* @param {number} length - Length of data in bytes to copy from current offset
|
|
@@ -6960,6 +6972,7 @@ export class biwriter {
|
|
|
6960
6972
|
//
|
|
6961
6973
|
/**
|
|
6962
6974
|
* Inserts data into data
|
|
6975
|
+
*
|
|
6963
6976
|
* Note: Must be same data type as supplied data. Errors on strict mode.
|
|
6964
6977
|
*
|
|
6965
6978
|
* @param {Buffer|Uint8Array} data - ``Uint8Array`` or ``Buffer`` to add to data
|
|
@@ -6967,10 +6980,11 @@ export class biwriter {
|
|
|
6967
6980
|
* @param {number} offset - Byte position to add at (defaults to current position)
|
|
6968
6981
|
*/
|
|
6969
6982
|
insert(data, consume, offset) {
|
|
6970
|
-
return addData(this, data, consume || false, offset || this.offset);
|
|
6983
|
+
return addData(this, data, consume || false, offset || this.offset, false);
|
|
6971
6984
|
}
|
|
6972
6985
|
/**
|
|
6973
6986
|
* Inserts data into data
|
|
6987
|
+
*
|
|
6974
6988
|
* Note: Must be same data type as supplied data. Errors on strict mode.
|
|
6975
6989
|
*
|
|
6976
6990
|
* @param {Buffer|Uint8Array} data - ``Uint8Array`` or ``Buffer`` to add to data
|
|
@@ -6978,10 +6992,11 @@ export class biwriter {
|
|
|
6978
6992
|
* @param {number} offset - Byte position to add at (defaults to current position)
|
|
6979
6993
|
*/
|
|
6980
6994
|
place(data, consume, offset) {
|
|
6981
|
-
return addData(this, data, consume || false, offset || this.offset);
|
|
6995
|
+
return addData(this, data, consume || false, offset || this.offset, false);
|
|
6982
6996
|
}
|
|
6983
6997
|
/**
|
|
6984
6998
|
* Replaces data in data
|
|
6999
|
+
*
|
|
6985
7000
|
* Note: Must be same data type as supplied data. Errors on strict mode.
|
|
6986
7001
|
*
|
|
6987
7002
|
* @param {Buffer|Uint8Array} data - ``Uint8Array`` or ``Buffer`` to replace in data
|
|
@@ -6993,6 +7008,7 @@ export class biwriter {
|
|
|
6993
7008
|
}
|
|
6994
7009
|
/**
|
|
6995
7010
|
* Replaces data in data
|
|
7011
|
+
*
|
|
6996
7012
|
* Note: Must be same data type as supplied data. Errors on strict mode.
|
|
6997
7013
|
*
|
|
6998
7014
|
* @param {Buffer|Uint8Array} data - ``Uint8Array`` or ``Buffer`` to replace in data
|
|
@@ -7004,43 +7020,47 @@ export class biwriter {
|
|
|
7004
7020
|
}
|
|
7005
7021
|
/**
|
|
7006
7022
|
* Adds data to start of supplied data
|
|
7023
|
+
*
|
|
7007
7024
|
* Note: Must be same data type as supplied data. Errors on strict mode.
|
|
7008
7025
|
*
|
|
7009
7026
|
* @param {Buffer|Uint8Array} data - ``Uint8Array`` or ``Buffer`` to add to data
|
|
7010
7027
|
* @param {boolean} consume - Move current write position to end of data (default false)
|
|
7011
7028
|
*/
|
|
7012
7029
|
unshift(data, consume) {
|
|
7013
|
-
return addData(this, data, consume || false, 0);
|
|
7030
|
+
return addData(this, data, consume || false, 0, false);
|
|
7014
7031
|
}
|
|
7015
7032
|
/**
|
|
7016
7033
|
* Adds data to start of supplied data
|
|
7034
|
+
*
|
|
7017
7035
|
* Note: Must be same data type as supplied data. Errors on strict mode.
|
|
7018
7036
|
*
|
|
7019
7037
|
* @param {Buffer|Uint8Array} data - ``Uint8Array`` or ``Buffer`` to add to data
|
|
7020
7038
|
* @param {boolean} consume - Move current write position to end of data (default false)
|
|
7021
7039
|
*/
|
|
7022
7040
|
prepend(data, consume) {
|
|
7023
|
-
return addData(this, data, consume || false, 0);
|
|
7041
|
+
return addData(this, data, consume || false, 0, false);
|
|
7024
7042
|
}
|
|
7025
7043
|
/**
|
|
7026
7044
|
* Adds data to end of supplied data
|
|
7045
|
+
*
|
|
7027
7046
|
* Note: Must be same data type as supplied data. Errors on strict mode.
|
|
7028
7047
|
*
|
|
7029
7048
|
* @param {Buffer|Uint8Array} data - ``Uint8Array`` or ``Buffer`` to add to data
|
|
7030
7049
|
* @param {boolean} consume - Move current write position to end of data (default false)
|
|
7031
7050
|
*/
|
|
7032
7051
|
push(data, consume) {
|
|
7033
|
-
return addData(this, data, consume || false, this.size);
|
|
7052
|
+
return addData(this, data, consume || false, this.size, false);
|
|
7034
7053
|
}
|
|
7035
7054
|
/**
|
|
7036
7055
|
* Adds data to end of supplied data
|
|
7056
|
+
*
|
|
7037
7057
|
* Note: Must be same data type as supplied data. Errors on strict mode.
|
|
7038
7058
|
*
|
|
7039
7059
|
* @param {Buffer|Uint8Array} data - ``Uint8Array`` or ``Buffer`` to add to data
|
|
7040
7060
|
* @param {boolean} consume - Move current write position to end of data (default false)
|
|
7041
7061
|
*/
|
|
7042
7062
|
append(data, consume) {
|
|
7043
|
-
return addData(this, data, consume || false, this.size);
|
|
7063
|
+
return addData(this, data, consume || false, this.size, false);
|
|
7044
7064
|
}
|
|
7045
7065
|
//
|
|
7046
7066
|
//finishing
|