bireader 1.0.45 → 1.0.46

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/esm/index.mjs CHANGED
@@ -170,7 +170,7 @@ 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;
173
+ needed_size = (offset || _this.offset) + data.length;
174
174
  }
175
175
  if (needed_size > _this.size) {
176
176
  if (_this.strict == false) {
@@ -183,35 +183,29 @@ function addData(_this, data, consume, offset, replace) {
183
183
  _this.size = _this.data.length;
184
184
  }
185
185
  if (replace) {
186
+ const part1 = _this.data.subarray(0, needed_size - data.length);
187
+ const part2 = _this.data.subarray(needed_size, _this.size);
186
188
  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
189
  _this.data = Buffer.concat([part1, data, part2]);
190
- _this.size = _this.data.length;
191
190
  }
192
191
  else {
193
- const part1 = _this.data.subarray(0, needed_size - data.length);
194
- const part2 = _this.data.subarray(needed_size, _this.size);
195
192
  _this.data = new Uint8Array([...part1, ...data, ...part2]);
196
- _this.size = _this.data.length;
197
193
  }
194
+ _this.size = _this.data.length;
198
195
  }
199
196
  else {
197
+ const part1 = _this.data.subarray(0, needed_size);
198
+ const part2 = _this.data.subarray(needed_size, _this.size);
200
199
  if (isBuffer(_this.data)) {
201
- const part1 = _this.data.subarray(0, needed_size);
202
- const part2 = _this.data.subarray(needed_size, _this.size);
203
200
  _this.data = Buffer.concat([part1, data, part2]);
204
- _this.size = _this.data.length;
205
201
  }
206
202
  else {
207
- const part1 = _this.data.subarray(0, needed_size);
208
- const part2 = _this.data.subarray(needed_size, _this.size);
209
203
  _this.data = new Uint8Array([...part1, ...data, ...part2]);
210
- _this.size = _this.data.length;
211
204
  }
205
+ _this.size = _this.data.length;
212
206
  }
213
207
  if (consume) {
214
- _this.offset = needed_size;
208
+ _this.offset = (offset || _this.offset) + data.length;
215
209
  _this.bitoffset = 0;
216
210
  }
217
211
  }
@@ -2382,7 +2376,7 @@ export class bireader {
2382
2376
  * @param {number} offset - Byte position to add at (defaults to current position)
2383
2377
  */
2384
2378
  insert(data, consume, offset) {
2385
- return addData(this, data, consume || false, offset || this.offset);
2379
+ return addData(this, data, consume || false, offset || this.offset, false);
2386
2380
  }
2387
2381
  /**
2388
2382
  * Inserts data into data
@@ -2393,7 +2387,7 @@ export class bireader {
2393
2387
  * @param {number} offset - Byte position to add at (defaults to current position)
2394
2388
  */
2395
2389
  place(data, consume, offset) {
2396
- return addData(this, data, consume || false, offset || this.offset);
2390
+ return addData(this, data, consume || false, offset || this.offset, false);
2397
2391
  }
2398
2392
  /**
2399
2393
  * Replaces data in data
@@ -2425,7 +2419,7 @@ export class bireader {
2425
2419
  * @param {boolean} consume - Move current write position to end of data (default false)
2426
2420
  */
2427
2421
  unshift(data, consume) {
2428
- return addData(this, data, consume || false, 0);
2422
+ return addData(this, data, consume || false, 0, false);
2429
2423
  }
2430
2424
  /**
2431
2425
  * Adds data to start of supplied data
@@ -2435,7 +2429,7 @@ export class bireader {
2435
2429
  * @param {boolean} consume - Move current write position to end of data (default false)
2436
2430
  */
2437
2431
  prepend(data, consume) {
2438
- return addData(this, data, consume || false, 0);
2432
+ return addData(this, data, consume || false, 0, false);
2439
2433
  }
2440
2434
  /**
2441
2435
  * Adds data to end of supplied data
@@ -2445,7 +2439,7 @@ export class bireader {
2445
2439
  * @param {boolean} consume - Move current write position to end of data (default false)
2446
2440
  */
2447
2441
  push(data, consume) {
2448
- return addData(this, data, consume || false, this.size);
2442
+ return addData(this, data, consume || false, this.size, false);
2449
2443
  }
2450
2444
  /**
2451
2445
  * Adds data to end of supplied data
@@ -2455,7 +2449,7 @@ export class bireader {
2455
2449
  * @param {boolean} consume - Move current write position to end of data (default false)
2456
2450
  */
2457
2451
  append(data, consume) {
2458
- return addData(this, data, consume || false, this.size);
2452
+ return addData(this, data, consume || false, this.size, false);
2459
2453
  }
2460
2454
  //
2461
2455
  //finishing
@@ -6967,7 +6961,7 @@ export class biwriter {
6967
6961
  * @param {number} offset - Byte position to add at (defaults to current position)
6968
6962
  */
6969
6963
  insert(data, consume, offset) {
6970
- return addData(this, data, consume || false, offset || this.offset);
6964
+ return addData(this, data, consume || false, offset || this.offset, false);
6971
6965
  }
6972
6966
  /**
6973
6967
  * Inserts data into data
@@ -6978,7 +6972,7 @@ export class biwriter {
6978
6972
  * @param {number} offset - Byte position to add at (defaults to current position)
6979
6973
  */
6980
6974
  place(data, consume, offset) {
6981
- return addData(this, data, consume || false, offset || this.offset);
6975
+ return addData(this, data, consume || false, offset || this.offset, false);
6982
6976
  }
6983
6977
  /**
6984
6978
  * Replaces data in data
@@ -7010,7 +7004,7 @@ export class biwriter {
7010
7004
  * @param {boolean} consume - Move current write position to end of data (default false)
7011
7005
  */
7012
7006
  unshift(data, consume) {
7013
- return addData(this, data, consume || false, 0);
7007
+ return addData(this, data, consume || false, 0, false);
7014
7008
  }
7015
7009
  /**
7016
7010
  * Adds data to start of supplied data
@@ -7020,7 +7014,7 @@ export class biwriter {
7020
7014
  * @param {boolean} consume - Move current write position to end of data (default false)
7021
7015
  */
7022
7016
  prepend(data, consume) {
7023
- return addData(this, data, consume || false, 0);
7017
+ return addData(this, data, consume || false, 0, false);
7024
7018
  }
7025
7019
  /**
7026
7020
  * Adds data to end of supplied data
@@ -7030,7 +7024,7 @@ export class biwriter {
7030
7024
  * @param {boolean} consume - Move current write position to end of data (default false)
7031
7025
  */
7032
7026
  push(data, consume) {
7033
- return addData(this, data, consume || false, this.size);
7027
+ return addData(this, data, consume || false, this.size, false);
7034
7028
  }
7035
7029
  /**
7036
7030
  * Adds data to end of supplied data
@@ -7040,7 +7034,7 @@ export class biwriter {
7040
7034
  * @param {boolean} consume - Move current write position to end of data (default false)
7041
7035
  */
7042
7036
  append(data, consume) {
7043
- return addData(this, data, consume || false, this.size);
7037
+ return addData(this, data, consume || false, this.size, false);
7044
7038
  }
7045
7039
  //
7046
7040
  //finishing
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "bireader",
3
- "version": "1.0.45",
3
+ "version": "1.0.46",
4
4
  "description": "Read and write data in binary",
5
5
  "module": "lib/esm/index.mjs",
6
6
  "main": "lib/cjs/index.js",