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/cjs/index.js
CHANGED
|
@@ -173,48 +173,32 @@ function addData(_this, data, consume, offset, replace) {
|
|
|
173
173
|
}
|
|
174
174
|
var needed_size = offset || _this.offset;
|
|
175
175
|
if (replace) {
|
|
176
|
-
needed_size = offset || _this.offset + data.length;
|
|
177
|
-
}
|
|
178
|
-
if (needed_size > _this.size) {
|
|
179
|
-
if (_this.strict == false) {
|
|
180
|
-
_this.extendArray(needed_size - _this.size);
|
|
181
|
-
}
|
|
182
|
-
else {
|
|
183
|
-
_this.errorDump ? "\x1b[31m[Error]\x1b[0m: hexdump:\n" + _this.hexdump() : "";
|
|
184
|
-
throw new Error("\x1b[33m[Strict mode]\x1b[0m: End offset outside of data: endOffset" + needed_size + " of " + _this.size);
|
|
185
|
-
}
|
|
186
|
-
_this.size = _this.data.length;
|
|
176
|
+
needed_size = (offset || _this.offset) + data.length;
|
|
187
177
|
}
|
|
188
178
|
if (replace) {
|
|
179
|
+
const part1 = _this.data.subarray(0, needed_size - data.length);
|
|
180
|
+
const part2 = _this.data.subarray(needed_size, _this.size);
|
|
189
181
|
if (isBuffer(_this.data)) {
|
|
190
|
-
const part1 = _this.data.subarray(0, needed_size - data.length);
|
|
191
|
-
const part2 = _this.data.subarray(needed_size, _this.size);
|
|
192
182
|
_this.data = Buffer.concat([part1, data, part2]);
|
|
193
|
-
_this.size = _this.data.length;
|
|
194
183
|
}
|
|
195
184
|
else {
|
|
196
|
-
const part1 = _this.data.subarray(0, needed_size - data.length);
|
|
197
|
-
const part2 = _this.data.subarray(needed_size, _this.size);
|
|
198
185
|
_this.data = new Uint8Array([...part1, ...data, ...part2]);
|
|
199
|
-
_this.size = _this.data.length;
|
|
200
186
|
}
|
|
187
|
+
_this.size = _this.data.length;
|
|
201
188
|
}
|
|
202
189
|
else {
|
|
190
|
+
const part1 = _this.data.subarray(0, needed_size);
|
|
191
|
+
const part2 = _this.data.subarray(needed_size, _this.size);
|
|
203
192
|
if (isBuffer(_this.data)) {
|
|
204
|
-
const part1 = _this.data.subarray(0, needed_size);
|
|
205
|
-
const part2 = _this.data.subarray(needed_size, _this.size);
|
|
206
193
|
_this.data = Buffer.concat([part1, data, part2]);
|
|
207
|
-
_this.size = _this.data.length;
|
|
208
194
|
}
|
|
209
195
|
else {
|
|
210
|
-
const part1 = _this.data.subarray(0, needed_size);
|
|
211
|
-
const part2 = _this.data.subarray(needed_size, _this.size);
|
|
212
196
|
_this.data = new Uint8Array([...part1, ...data, ...part2]);
|
|
213
|
-
_this.size = _this.data.length;
|
|
214
197
|
}
|
|
198
|
+
_this.size = _this.data.length;
|
|
215
199
|
}
|
|
216
200
|
if (consume) {
|
|
217
|
-
_this.offset =
|
|
201
|
+
_this.offset = (offset || _this.offset) + data.length;
|
|
218
202
|
_this.bitoffset = 0;
|
|
219
203
|
}
|
|
220
204
|
}
|
|
@@ -1769,6 +1753,7 @@ class bireader {
|
|
|
1769
1753
|
}
|
|
1770
1754
|
/**
|
|
1771
1755
|
* Offset current byte or bit position
|
|
1756
|
+
*
|
|
1772
1757
|
* Note: Will extend array if strict mode is off and outside of max size
|
|
1773
1758
|
*
|
|
1774
1759
|
* @param {number} bytes - Bytes to skip
|
|
@@ -1779,6 +1764,7 @@ class bireader {
|
|
|
1779
1764
|
}
|
|
1780
1765
|
/**
|
|
1781
1766
|
* Offset current byte or bit position
|
|
1767
|
+
*
|
|
1782
1768
|
* Note: Will extend array if strict mode is off and outside of max size
|
|
1783
1769
|
*
|
|
1784
1770
|
* @param {number} bytes - Bytes to skip
|
|
@@ -1792,6 +1778,7 @@ class bireader {
|
|
|
1792
1778
|
//
|
|
1793
1779
|
/**
|
|
1794
1780
|
* Change position directly to address
|
|
1781
|
+
*
|
|
1795
1782
|
* Note: Will extend array if strict mode is off and outside of max size
|
|
1796
1783
|
*
|
|
1797
1784
|
* @param {number} byte - byte to set to
|
|
@@ -1802,6 +1789,7 @@ class bireader {
|
|
|
1802
1789
|
}
|
|
1803
1790
|
/**
|
|
1804
1791
|
* Offset current byte or bit position
|
|
1792
|
+
*
|
|
1805
1793
|
* Note: Will extend array if strict mode is off and outside of max size
|
|
1806
1794
|
*
|
|
1807
1795
|
* @param {number} bytes - Bytes to skip
|
|
@@ -1812,6 +1800,7 @@ class bireader {
|
|
|
1812
1800
|
}
|
|
1813
1801
|
/**
|
|
1814
1802
|
* Change position directly to address
|
|
1803
|
+
*
|
|
1815
1804
|
* Note: Will extend array if strict mode is off and outside of max size
|
|
1816
1805
|
*
|
|
1817
1806
|
* @param {number} byte - byte to set to
|
|
@@ -1822,6 +1811,7 @@ class bireader {
|
|
|
1822
1811
|
}
|
|
1823
1812
|
/**
|
|
1824
1813
|
* Change position directly to address
|
|
1814
|
+
*
|
|
1825
1815
|
* Note: Will extend array if strict mode is off and outside of max size
|
|
1826
1816
|
*
|
|
1827
1817
|
* @param {number} byte - byte to set to
|
|
@@ -2263,6 +2253,7 @@ class bireader {
|
|
|
2263
2253
|
//
|
|
2264
2254
|
/**
|
|
2265
2255
|
* Deletes part of data from start to current byte position unless supplied, returns removed
|
|
2256
|
+
*
|
|
2266
2257
|
* Note: Errors in strict mode
|
|
2267
2258
|
*
|
|
2268
2259
|
* @param {number} startOffset - Start location (default 0)
|
|
@@ -2275,6 +2266,7 @@ class bireader {
|
|
|
2275
2266
|
}
|
|
2276
2267
|
/**
|
|
2277
2268
|
* Deletes part of data from current byte position to end, returns removed
|
|
2269
|
+
*
|
|
2278
2270
|
* Note: Errors in strict mode
|
|
2279
2271
|
*
|
|
2280
2272
|
* @returns {Buffer|Uint8Array} Removed data as ``Buffer`` or ``Uint8Array``
|
|
@@ -2284,6 +2276,7 @@ class bireader {
|
|
|
2284
2276
|
}
|
|
2285
2277
|
/**
|
|
2286
2278
|
* Deletes part of data from current byte position to end, returns removed
|
|
2279
|
+
*
|
|
2287
2280
|
* Note: Errors in strict mode
|
|
2288
2281
|
*
|
|
2289
2282
|
* @returns {Buffer|Uint8Array} Removed data as ``Buffer`` or ``Uint8Array``
|
|
@@ -2293,6 +2286,7 @@ class bireader {
|
|
|
2293
2286
|
}
|
|
2294
2287
|
/**
|
|
2295
2288
|
* Deletes part of data from current byte position to supplied length, returns removed
|
|
2289
|
+
*
|
|
2296
2290
|
* Note: Errors in strict mode
|
|
2297
2291
|
*
|
|
2298
2292
|
* @param {number} length - Length of data in bytes to remove
|
|
@@ -2342,6 +2336,7 @@ class bireader {
|
|
|
2342
2336
|
}
|
|
2343
2337
|
/**
|
|
2344
2338
|
* Extract data from current position to length supplied
|
|
2339
|
+
*
|
|
2345
2340
|
* Note: Does not affect supplied data
|
|
2346
2341
|
*
|
|
2347
2342
|
* @param {number} length - Length of data in bytes to copy from current offset
|
|
@@ -2353,6 +2348,7 @@ class bireader {
|
|
|
2353
2348
|
}
|
|
2354
2349
|
/**
|
|
2355
2350
|
* Extract data from current position to length supplied
|
|
2351
|
+
*
|
|
2356
2352
|
* Note: Does not affect supplied data
|
|
2357
2353
|
*
|
|
2358
2354
|
* @param {number} length - Length of data in bytes to copy from current offset
|
|
@@ -2364,6 +2360,7 @@ class bireader {
|
|
|
2364
2360
|
}
|
|
2365
2361
|
/**
|
|
2366
2362
|
* Extract data from current position to length supplied
|
|
2363
|
+
*
|
|
2367
2364
|
* Note: Does not affect supplied data
|
|
2368
2365
|
*
|
|
2369
2366
|
* @param {number} length - Length of data in bytes to copy from current offset
|
|
@@ -2378,6 +2375,7 @@ class bireader {
|
|
|
2378
2375
|
//
|
|
2379
2376
|
/**
|
|
2380
2377
|
* Inserts data into data
|
|
2378
|
+
*
|
|
2381
2379
|
* Note: Must be same data type as supplied data. Errors on strict mode.
|
|
2382
2380
|
*
|
|
2383
2381
|
* @param {Buffer|Uint8Array} data - ``Uint8Array`` or ``Buffer`` to add to data
|
|
@@ -2385,10 +2383,11 @@ class bireader {
|
|
|
2385
2383
|
* @param {number} offset - Byte position to add at (defaults to current position)
|
|
2386
2384
|
*/
|
|
2387
2385
|
insert(data, consume, offset) {
|
|
2388
|
-
return addData(this, data, consume || false, offset || this.offset);
|
|
2386
|
+
return addData(this, data, consume || false, offset || this.offset, false);
|
|
2389
2387
|
}
|
|
2390
2388
|
/**
|
|
2391
2389
|
* Inserts data into data
|
|
2390
|
+
*
|
|
2392
2391
|
* Note: Must be same data type as supplied data. Errors on strict mode.
|
|
2393
2392
|
*
|
|
2394
2393
|
* @param {Buffer|Uint8Array} data - ``Uint8Array`` or ``Buffer`` to add to data
|
|
@@ -2396,10 +2395,11 @@ class bireader {
|
|
|
2396
2395
|
* @param {number} offset - Byte position to add at (defaults to current position)
|
|
2397
2396
|
*/
|
|
2398
2397
|
place(data, consume, offset) {
|
|
2399
|
-
return addData(this, data, consume || false, offset || this.offset);
|
|
2398
|
+
return addData(this, data, consume || false, offset || this.offset, false);
|
|
2400
2399
|
}
|
|
2401
2400
|
/**
|
|
2402
2401
|
* Replaces data in data
|
|
2402
|
+
*
|
|
2403
2403
|
* Note: Must be same data type as supplied data. Errors on strict mode.
|
|
2404
2404
|
*
|
|
2405
2405
|
* @param {Buffer|Uint8Array} data - ``Uint8Array`` or ``Buffer`` to replace in data
|
|
@@ -2411,6 +2411,7 @@ class bireader {
|
|
|
2411
2411
|
}
|
|
2412
2412
|
/**
|
|
2413
2413
|
* Replaces data in data
|
|
2414
|
+
*
|
|
2414
2415
|
* Note: Must be same data type as supplied data. Errors on strict mode.
|
|
2415
2416
|
*
|
|
2416
2417
|
* @param {Buffer|Uint8Array} data - ``Uint8Array`` or ``Buffer`` to replace in data
|
|
@@ -2422,43 +2423,47 @@ class bireader {
|
|
|
2422
2423
|
}
|
|
2423
2424
|
/**
|
|
2424
2425
|
* Adds data to start of supplied data
|
|
2426
|
+
*
|
|
2425
2427
|
* Note: Must be same data type as supplied data. Errors on strict mode.
|
|
2426
2428
|
*
|
|
2427
2429
|
* @param {Buffer|Uint8Array} data - ``Uint8Array`` or ``Buffer`` to add to data
|
|
2428
2430
|
* @param {boolean} consume - Move current write position to end of data (default false)
|
|
2429
2431
|
*/
|
|
2430
2432
|
unshift(data, consume) {
|
|
2431
|
-
return addData(this, data, consume || false, 0);
|
|
2433
|
+
return addData(this, data, consume || false, 0, false);
|
|
2432
2434
|
}
|
|
2433
2435
|
/**
|
|
2434
2436
|
* Adds data to start of supplied data
|
|
2437
|
+
*
|
|
2435
2438
|
* Note: Must be same data type as supplied data. Errors on strict mode.
|
|
2436
2439
|
*
|
|
2437
2440
|
* @param {Buffer|Uint8Array} data - ``Uint8Array`` or ``Buffer`` to add to data
|
|
2438
2441
|
* @param {boolean} consume - Move current write position to end of data (default false)
|
|
2439
2442
|
*/
|
|
2440
2443
|
prepend(data, consume) {
|
|
2441
|
-
return addData(this, data, consume || false, 0);
|
|
2444
|
+
return addData(this, data, consume || false, 0, false);
|
|
2442
2445
|
}
|
|
2443
2446
|
/**
|
|
2444
2447
|
* Adds data to end of supplied data
|
|
2448
|
+
*
|
|
2445
2449
|
* Note: Must be same data type as supplied data. Errors on strict mode.
|
|
2446
2450
|
*
|
|
2447
2451
|
* @param {Buffer|Uint8Array} data - ``Uint8Array`` or ``Buffer`` to add to data
|
|
2448
2452
|
* @param {boolean} consume - Move current write position to end of data (default false)
|
|
2449
2453
|
*/
|
|
2450
2454
|
push(data, consume) {
|
|
2451
|
-
return addData(this, data, consume || false, this.size);
|
|
2455
|
+
return addData(this, data, consume || false, this.size, false);
|
|
2452
2456
|
}
|
|
2453
2457
|
/**
|
|
2454
2458
|
* Adds data to end of supplied data
|
|
2459
|
+
*
|
|
2455
2460
|
* Note: Must be same data type as supplied data. Errors on strict mode.
|
|
2456
2461
|
*
|
|
2457
2462
|
* @param {Buffer|Uint8Array} data - ``Uint8Array`` or ``Buffer`` to add to data
|
|
2458
2463
|
* @param {boolean} consume - Move current write position to end of data (default false)
|
|
2459
2464
|
*/
|
|
2460
2465
|
append(data, consume) {
|
|
2461
|
-
return addData(this, data, consume || false, this.size);
|
|
2466
|
+
return addData(this, data, consume || false, this.size, false);
|
|
2462
2467
|
}
|
|
2463
2468
|
//
|
|
2464
2469
|
//finishing
|
|
@@ -6849,6 +6854,7 @@ class biwriter {
|
|
|
6849
6854
|
//
|
|
6850
6855
|
/**
|
|
6851
6856
|
* Deletes part of data from start to current byte position unless supplied, returns removed
|
|
6857
|
+
*
|
|
6852
6858
|
* Note: Errors in strict mode
|
|
6853
6859
|
*
|
|
6854
6860
|
* @param {number} startOffset - Start location (default 0)
|
|
@@ -6861,6 +6867,7 @@ class biwriter {
|
|
|
6861
6867
|
}
|
|
6862
6868
|
/**
|
|
6863
6869
|
* Deletes part of data from current byte position to end, returns removed
|
|
6870
|
+
*
|
|
6864
6871
|
* Note: Errors in strict mode
|
|
6865
6872
|
*
|
|
6866
6873
|
* @returns {Buffer|Uint8Array} Removed data as ``Buffer`` or ``Uint8Array``
|
|
@@ -6879,6 +6886,7 @@ class biwriter {
|
|
|
6879
6886
|
}
|
|
6880
6887
|
/**
|
|
6881
6888
|
* Deletes part of data from current byte position to supplied length, returns removed
|
|
6889
|
+
*
|
|
6882
6890
|
* Note: Errors in strict mode
|
|
6883
6891
|
*
|
|
6884
6892
|
* @param {number} length - Length of data in bytes to remove
|
|
@@ -6890,6 +6898,7 @@ class biwriter {
|
|
|
6890
6898
|
}
|
|
6891
6899
|
/**
|
|
6892
6900
|
* Deletes part of data from current position to supplied length, returns removed
|
|
6901
|
+
*
|
|
6893
6902
|
* Note: Only works in strict mode
|
|
6894
6903
|
*
|
|
6895
6904
|
* @param {number} length - Length of data in bytes to remove
|
|
@@ -6928,6 +6937,7 @@ class biwriter {
|
|
|
6928
6937
|
}
|
|
6929
6938
|
/**
|
|
6930
6939
|
* Extract data from current position to length supplied
|
|
6940
|
+
*
|
|
6931
6941
|
* Note: Does not affect supplied data
|
|
6932
6942
|
*
|
|
6933
6943
|
* @param {number} length - Length of data in bytes to copy from current offset
|
|
@@ -6939,6 +6949,7 @@ class biwriter {
|
|
|
6939
6949
|
}
|
|
6940
6950
|
/**
|
|
6941
6951
|
* Extract data from current position to length supplied
|
|
6952
|
+
*
|
|
6942
6953
|
* Note: Does not affect supplied data
|
|
6943
6954
|
*
|
|
6944
6955
|
* @param {number} length - Length of data in bytes to copy from current offset
|
|
@@ -6950,6 +6961,7 @@ class biwriter {
|
|
|
6950
6961
|
}
|
|
6951
6962
|
/**
|
|
6952
6963
|
* Extract data from current position to length supplied
|
|
6964
|
+
*
|
|
6953
6965
|
* Note: Does not affect supplied data
|
|
6954
6966
|
*
|
|
6955
6967
|
* @param {number} length - Length of data in bytes to copy from current offset
|
|
@@ -6964,6 +6976,7 @@ class biwriter {
|
|
|
6964
6976
|
//
|
|
6965
6977
|
/**
|
|
6966
6978
|
* Inserts data into data
|
|
6979
|
+
*
|
|
6967
6980
|
* Note: Must be same data type as supplied data. Errors on strict mode.
|
|
6968
6981
|
*
|
|
6969
6982
|
* @param {Buffer|Uint8Array} data - ``Uint8Array`` or ``Buffer`` to add to data
|
|
@@ -6971,10 +6984,11 @@ class biwriter {
|
|
|
6971
6984
|
* @param {number} offset - Byte position to add at (defaults to current position)
|
|
6972
6985
|
*/
|
|
6973
6986
|
insert(data, consume, offset) {
|
|
6974
|
-
return addData(this, data, consume || false, offset || this.offset);
|
|
6987
|
+
return addData(this, data, consume || false, offset || this.offset, false);
|
|
6975
6988
|
}
|
|
6976
6989
|
/**
|
|
6977
6990
|
* Inserts data into data
|
|
6991
|
+
*
|
|
6978
6992
|
* Note: Must be same data type as supplied data. Errors on strict mode.
|
|
6979
6993
|
*
|
|
6980
6994
|
* @param {Buffer|Uint8Array} data - ``Uint8Array`` or ``Buffer`` to add to data
|
|
@@ -6982,10 +6996,11 @@ class biwriter {
|
|
|
6982
6996
|
* @param {number} offset - Byte position to add at (defaults to current position)
|
|
6983
6997
|
*/
|
|
6984
6998
|
place(data, consume, offset) {
|
|
6985
|
-
return addData(this, data, consume || false, offset || this.offset);
|
|
6999
|
+
return addData(this, data, consume || false, offset || this.offset, false);
|
|
6986
7000
|
}
|
|
6987
7001
|
/**
|
|
6988
7002
|
* Replaces data in data
|
|
7003
|
+
*
|
|
6989
7004
|
* Note: Must be same data type as supplied data. Errors on strict mode.
|
|
6990
7005
|
*
|
|
6991
7006
|
* @param {Buffer|Uint8Array} data - ``Uint8Array`` or ``Buffer`` to replace in data
|
|
@@ -6997,6 +7012,7 @@ class biwriter {
|
|
|
6997
7012
|
}
|
|
6998
7013
|
/**
|
|
6999
7014
|
* Replaces data in data
|
|
7015
|
+
*
|
|
7000
7016
|
* Note: Must be same data type as supplied data. Errors on strict mode.
|
|
7001
7017
|
*
|
|
7002
7018
|
* @param {Buffer|Uint8Array} data - ``Uint8Array`` or ``Buffer`` to replace in data
|
|
@@ -7008,43 +7024,47 @@ class biwriter {
|
|
|
7008
7024
|
}
|
|
7009
7025
|
/**
|
|
7010
7026
|
* Adds data to start of supplied data
|
|
7027
|
+
*
|
|
7011
7028
|
* Note: Must be same data type as supplied data. Errors on strict mode.
|
|
7012
7029
|
*
|
|
7013
7030
|
* @param {Buffer|Uint8Array} data - ``Uint8Array`` or ``Buffer`` to add to data
|
|
7014
7031
|
* @param {boolean} consume - Move current write position to end of data (default false)
|
|
7015
7032
|
*/
|
|
7016
7033
|
unshift(data, consume) {
|
|
7017
|
-
return addData(this, data, consume || false, 0);
|
|
7034
|
+
return addData(this, data, consume || false, 0, false);
|
|
7018
7035
|
}
|
|
7019
7036
|
/**
|
|
7020
7037
|
* Adds data to start of supplied data
|
|
7038
|
+
*
|
|
7021
7039
|
* Note: Must be same data type as supplied data. Errors on strict mode.
|
|
7022
7040
|
*
|
|
7023
7041
|
* @param {Buffer|Uint8Array} data - ``Uint8Array`` or ``Buffer`` to add to data
|
|
7024
7042
|
* @param {boolean} consume - Move current write position to end of data (default false)
|
|
7025
7043
|
*/
|
|
7026
7044
|
prepend(data, consume) {
|
|
7027
|
-
return addData(this, data, consume || false, 0);
|
|
7045
|
+
return addData(this, data, consume || false, 0, false);
|
|
7028
7046
|
}
|
|
7029
7047
|
/**
|
|
7030
7048
|
* Adds data to end of supplied data
|
|
7049
|
+
*
|
|
7031
7050
|
* Note: Must be same data type as supplied data. Errors on strict mode.
|
|
7032
7051
|
*
|
|
7033
7052
|
* @param {Buffer|Uint8Array} data - ``Uint8Array`` or ``Buffer`` to add to data
|
|
7034
7053
|
* @param {boolean} consume - Move current write position to end of data (default false)
|
|
7035
7054
|
*/
|
|
7036
7055
|
push(data, consume) {
|
|
7037
|
-
return addData(this, data, consume || false, this.size);
|
|
7056
|
+
return addData(this, data, consume || false, this.size, false);
|
|
7038
7057
|
}
|
|
7039
7058
|
/**
|
|
7040
7059
|
* Adds data to end of supplied data
|
|
7060
|
+
*
|
|
7041
7061
|
* Note: Must be same data type as supplied data. Errors on strict mode.
|
|
7042
7062
|
*
|
|
7043
7063
|
* @param {Buffer|Uint8Array} data - ``Uint8Array`` or ``Buffer`` to add to data
|
|
7044
7064
|
* @param {boolean} consume - Move current write position to end of data (default false)
|
|
7045
7065
|
*/
|
|
7046
7066
|
append(data, consume) {
|
|
7047
|
-
return addData(this, data, consume || false, this.size);
|
|
7067
|
+
return addData(this, data, consume || false, this.size, false);
|
|
7048
7068
|
}
|
|
7049
7069
|
//
|
|
7050
7070
|
//finishing
|