bireader 3.1.13 → 3.1.15

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/dist/index.esm.js CHANGED
@@ -345,6 +345,7 @@ function checkSize(ctx, write_bytes, write_bit, offset) {
345
345
  function extendarray(ctx, to_padd) {
346
346
  if ((typeof Buffer !== 'undefined' && ctx.data instanceof Buffer)) {
347
347
  var paddbuffer = Buffer.alloc(to_padd);
348
+ // @ts-ignore
348
349
  ctx.data = Buffer.concat([ctx.data, paddbuffer]);
349
350
  }
350
351
  else {
@@ -380,6 +381,7 @@ function remove$1(ctx, startOffset, endOffset, consume, remove, fillValue) {
380
381
  const part1 = ctx.data.subarray(0, new_start);
381
382
  const part2 = ctx.data.subarray(new_offset, ctx.size);
382
383
  if (isBuffer(ctx.data)) {
384
+ // @ts-ignore
383
385
  ctx.data = Buffer.concat([part1, part2]);
384
386
  }
385
387
  else {
@@ -394,6 +396,7 @@ function remove$1(ctx, startOffset, endOffset, consume, remove, fillValue) {
394
396
  const replacement = new Array(data_removed.length).fill(fillValue & 0xff);
395
397
  if (isBuffer(ctx.data)) {
396
398
  const buff_placement = Buffer.from(replacement);
399
+ // @ts-ignore
397
400
  ctx.data = Buffer.concat([part1, buff_placement, part2]);
398
401
  }
399
402
  else {
@@ -420,6 +423,7 @@ function addData$1(ctx, data, consume, offset, replace) {
420
423
  throw new Error(`\x1b[33m[Strict mode]\x1b[0m: Can not insert data in strict mode. Use unrestrict() to enable.`);
421
424
  }
422
425
  if (typeof Buffer !== 'undefined' && data instanceof Buffer && !(ctx.data instanceof Buffer)) {
426
+ // @ts-ignore
423
427
  data = Buffer.from(data);
424
428
  }
425
429
  if (data instanceof Uint8Array && !(ctx.data instanceof Uint8Array)) {
@@ -431,6 +435,7 @@ function addData$1(ctx, data, consume, offset, replace) {
431
435
  const part1 = ctx.data.subarray(0, needed_size - data.length);
432
436
  const part2 = ctx.data.subarray(needed_size, ctx.size);
433
437
  if (isBuffer(ctx.data)) {
438
+ // @ts-ignore
434
439
  ctx.data = Buffer.concat([part1, data, part2]);
435
440
  }
436
441
  else {
@@ -443,6 +448,7 @@ function addData$1(ctx, data, consume, offset, replace) {
443
448
  const part1 = ctx.data.subarray(0, needed_size);
444
449
  const part2 = ctx.data.subarray(needed_size, ctx.size);
445
450
  if (isBuffer(ctx.data)) {
451
+ // @ts-ignore
446
452
  ctx.data = Buffer.concat([part1, data, part2]);
447
453
  }
448
454
  else {
@@ -1406,16 +1412,16 @@ function wint64$1(ctx, value, unsigned, endian) {
1406
1412
  }
1407
1413
  else {
1408
1414
  if (unsigned == undefined || unsigned == false) {
1409
- ctx.data[ctx.offset + (1 - i) * 4 + 0] = int32Array[i];
1410
- ctx.data[ctx.offset + (1 - i) * 4 + 1] = (int32Array[i] >> 8);
1411
- ctx.data[ctx.offset + (1 - i) * 4 + 2] = (int32Array[i] >> 16);
1412
- ctx.data[ctx.offset + (1 - i) * 4 + 3] = (int32Array[i] >> 24);
1415
+ ctx.data[ctx.offset + (1 - i) * 4 + 3] = int32Array[i];
1416
+ ctx.data[ctx.offset + (1 - i) * 4 + 2] = (int32Array[i] >> 8);
1417
+ ctx.data[ctx.offset + (1 - i) * 4 + 1] = (int32Array[i] >> 16);
1418
+ ctx.data[ctx.offset + (1 - i) * 4 + 0] = (int32Array[i] >> 24);
1413
1419
  }
1414
1420
  else {
1415
- ctx.data[ctx.offset + (1 - i) * 4 + 0] = int32Array[i] & 0xFF;
1416
- ctx.data[ctx.offset + (1 - i) * 4 + 1] = (int32Array[i] >> 8) & 0xFF;
1417
- ctx.data[ctx.offset + (1 - i) * 4 + 2] = (int32Array[i] >> 16) & 0xFF;
1418
- ctx.data[ctx.offset + (1 - i) * 4 + 3] = (int32Array[i] >> 24) & 0xFF;
1421
+ ctx.data[ctx.offset + (1 - i) * 4 + 3] = int32Array[i] & 0xFF;
1422
+ ctx.data[ctx.offset + (1 - i) * 4 + 2] = (int32Array[i] >> 8) & 0xFF;
1423
+ ctx.data[ctx.offset + (1 - i) * 4 + 1] = (int32Array[i] >> 16) & 0xFF;
1424
+ ctx.data[ctx.offset + (1 - i) * 4 + 0] = (int32Array[i] >> 24) & 0xFF;
1419
1425
  }
1420
1426
  }
1421
1427
  }
@@ -10593,6 +10599,17 @@ class BiWriter extends BiBase {
10593
10599
  ;
10594
10600
  }
10595
10601
 
10602
+ // browser hack
10603
+ if (Buffer == undefined) {
10604
+ Buffer = {
10605
+ // @ts-ignore
10606
+ isBuffer: (any) => { },
10607
+ // @ts-ignore
10608
+ from: (array) => { },
10609
+ // @ts-ignore
10610
+ alloc: (num) => { }
10611
+ };
10612
+ }
10596
10613
  function MAX_LENGTH() {
10597
10614
  return constants.MAX_LENGTH;
10598
10615
  }
@@ -10716,7 +10733,7 @@ function remove(ctx, startOffset, endOffset, consume, remove, fillValue) {
10716
10733
  var readStart = new_start;
10717
10734
  var amount = removedLength;
10718
10735
  const chunkSize = 64 * 1024; // 64 KB
10719
- const chunk = Buffer.alloc(chunkSize, fillValue & 0xff);
10736
+ const chunk = new Uint8Array(chunkSize).fill(fillValue & 0xff);
10720
10737
  while (amount) {
10721
10738
  const toWrite = Math.min(chunkSize, amount);
10722
10739
  const bytesWritten = fs.readSync(ctx.fd, chunk, 0, toWrite, readStart);
@@ -10733,7 +10750,7 @@ function remove(ctx, startOffset, endOffset, consume, remove, fillValue) {
10733
10750
  var readOffset = new_start;
10734
10751
  var writeOffset = 0;
10735
10752
  var amount = removedLength;
10736
- const chunk = Buffer.alloc(CHUNK_SIZE);
10753
+ const chunk = new Uint8Array(CHUNK_SIZE);
10737
10754
  const tempFd = fs.openSync(removeData, 'w+');
10738
10755
  while (amount) {
10739
10756
  const toRead = Math.min(CHUNK_SIZE, amount);
@@ -10764,7 +10781,7 @@ function remove(ctx, startOffset, endOffset, consume, remove, fillValue) {
10764
10781
  const removeData = ctx.filePath + NaN + startOffset + "_" + removedLength + ".removed";
10765
10782
  console.warn(`File size for extract is larger than the max Buffer Node can handle, creating new file ${removeData}`);
10766
10783
  const CHUNK_SIZE = 64 * 1024;
10767
- const chunk = Buffer.alloc(CHUNK_SIZE);
10784
+ const chunk = new Uint8Array(CHUNK_SIZE);
10768
10785
  // Copy removed to new file
10769
10786
  var readOffset = new_start;
10770
10787
  var writeOffset = 0;
@@ -10797,7 +10814,7 @@ function remove(ctx, startOffset, endOffset, consume, remove, fillValue) {
10797
10814
  const removedBuffer = ctx.read(new_start, removedLength, false);
10798
10815
  const end = new_start + removedLength;
10799
10816
  const chunkSize = 64 * 1024;
10800
- const buffer = Buffer.alloc(chunkSize);
10817
+ const buffer = new Uint8Array(chunkSize);
10801
10818
  let remaining = ctx.size - end;
10802
10819
  let readPos = end;
10803
10820
  while (remaining > 0) {
@@ -10823,15 +10840,15 @@ function remove(ctx, startOffset, endOffset, consume, remove, fillValue) {
10823
10840
  }
10824
10841
  else {
10825
10842
  if (fillValue != undefined) {
10826
- const removedBuffer = Buffer.alloc(removedLength);
10843
+ const removedBuffer = new Uint8Array(removedLength);
10827
10844
  removedBuffer.fill(fillValue & 0xff);
10828
10845
  fs.writeSync(ctx.fd, removedBuffer, 0, removedBuffer.length, new_start);
10829
10846
  if (consume == true) {
10830
10847
  ctx.offset = new_offset;
10831
10848
  ctx.bitoffset = 0;
10832
10849
  }
10833
- ctx.data = removedBuffer;
10834
- return removedBuffer;
10850
+ ctx.data = Buffer.from(removedBuffer);
10851
+ return ctx.data;
10835
10852
  }
10836
10853
  else {
10837
10854
  // just copying and returning data
@@ -10876,19 +10893,18 @@ function addData(ctx, data, consume, offset, replace) {
10876
10893
  if (!arraybuffcheck(data)) {
10877
10894
  throw new Error('Data must be a Uint8Array or Buffer');
10878
10895
  }
10879
- var buffer = data;
10880
- if (data instanceof Uint8Array) {
10881
- buffer = Buffer.from(data);
10896
+ if (Buffer.isBuffer(data)) {
10897
+ data = new Uint8Array(data);
10882
10898
  }
10883
10899
  if (replace) {
10884
10900
  // overwrite
10885
- fs.writeSync(ctx.fd, buffer, 0, buffer.length, offset);
10901
+ fs.writeSync(ctx.fd, data, 0, data.length, offset);
10886
10902
  ctx.updateSize();
10887
10903
  }
10888
10904
  else {
10889
10905
  // insert
10890
10906
  const chunkSize = 64 * 1024; // 64KB
10891
- const buffer = Buffer.alloc(chunkSize);
10907
+ const buffer = new Uint8Array(chunkSize);
10892
10908
  let remaining = originalSize - offset;
10893
10909
  let readPos = originalSize - chunkSize;
10894
10910
  while (remaining > 0) {
@@ -11294,7 +11310,7 @@ function ADD(ctx, add_key, start, end, consume) {
11294
11310
  function fString(ctx, searchString) {
11295
11311
  ctx.open();
11296
11312
  const chunkSize = 0x2000; // 8192 bytes
11297
- let lastChunk = Buffer.alloc(0);
11313
+ let lastChunk = new Uint8Array(0);
11298
11314
  const searchStringBuffer = new TextEncoder().encode(searchString);
11299
11315
  var start = ctx.offset;
11300
11316
  const strict_saver = ctx.strict;
@@ -11304,7 +11320,7 @@ function fString(ctx, searchString) {
11304
11320
  if (currentChunk.length === 0)
11305
11321
  break; // No more data to read
11306
11322
  // Concatenate the last part of the previous chunk with the current chunk
11307
- const combinedBuffer = Buffer.concat([lastChunk, currentChunk]);
11323
+ const combinedBuffer = Buffer.concat([lastChunk, new Uint8Array(currentChunk)]);
11308
11324
  // Search for the string in the combined buffer
11309
11325
  let offset = 0;
11310
11326
  while (offset <= combinedBuffer.length - searchStringBuffer.length) {
@@ -11317,7 +11333,7 @@ function fString(ctx, searchString) {
11317
11333
  //offset = index + 1; // Move to the next possible position
11318
11334
  }
11319
11335
  // Update the last chunk for the next iteration
11320
- lastChunk = currentChunk.subarray(-searchStringBuffer.length + 1);
11336
+ lastChunk = new Uint8Array(currentChunk.subarray(-searchStringBuffer.length + 1));
11321
11337
  start += currentChunk.length;
11322
11338
  }
11323
11339
  ctx.strict = strict_saver;
@@ -11326,7 +11342,7 @@ function fString(ctx, searchString) {
11326
11342
  function fNumber(ctx, targetNumber, bits, unsigned, endian) {
11327
11343
  ctx.open();
11328
11344
  const chunkSize = 0x2000; // 8192 bytes
11329
- let lastChunk = Buffer.alloc(0);
11345
+ let lastChunk = new Uint8Array(0);
11330
11346
  const totalBits = Math.floor(bits / 8);
11331
11347
  var start = ctx.offset;
11332
11348
  while (start < ctx.size) {
@@ -11334,7 +11350,7 @@ function fNumber(ctx, targetNumber, bits, unsigned, endian) {
11334
11350
  if (currentChunk.length === 0)
11335
11351
  break; // No more data to read
11336
11352
  // Concatenate the last part of the previous chunk with the current chunk
11337
- const combinedBuffer = Buffer.concat([lastChunk, currentChunk]);
11353
+ const combinedBuffer = Buffer.concat([lastChunk, new Uint8Array(currentChunk)]);
11338
11354
  // Process the combined buffer to find the target number
11339
11355
  for (let z = 0; z <= combinedBuffer.length - totalBits; z++) {
11340
11356
  let value = 0;
@@ -11372,7 +11388,7 @@ function fNumber(ctx, targetNumber, bits, unsigned, endian) {
11372
11388
  }
11373
11389
  }
11374
11390
  // Update the last chunk for the next iteration
11375
- lastChunk = combinedBuffer.subarray(-totalBits + 1);
11391
+ lastChunk = new Uint8Array(combinedBuffer.subarray(-totalBits + 1));
11376
11392
  start += currentChunk.length;
11377
11393
  }
11378
11394
  return -1; // number not found
@@ -11473,14 +11489,14 @@ function fFloat(ctx, targetNumber, endian) {
11473
11489
  function fBigInt(ctx, targetNumber, unsigned, endian) {
11474
11490
  ctx.open();
11475
11491
  const chunkSize = 0x2000; // 8192 bytes
11476
- let lastChunk = Buffer.alloc(0);
11492
+ let lastChunk = new Uint8Array(0);
11477
11493
  const targetBigInt = BigInt(targetNumber);
11478
11494
  while (ctx.offset < ctx.size) {
11479
11495
  const currentChunk = ctx.read(ctx.offset, Math.min(chunkSize, ctx.size - ctx.offset), false);
11480
11496
  if (currentChunk.length === 0)
11481
11497
  break; // No more data to read
11482
11498
  // Concatenate the last part of the previous chunk with the current chunk
11483
- const combinedBuffer = Buffer.concat([lastChunk, currentChunk]);
11499
+ const combinedBuffer = Buffer.concat([lastChunk, new Uint8Array(currentChunk)]);
11484
11500
  // Process the combined buffer to find the target BigInt
11485
11501
  for (let z = 0; z <= combinedBuffer.length - 8; z++) {
11486
11502
  let value = BigInt(0);
@@ -11504,7 +11520,7 @@ function fBigInt(ctx, targetNumber, unsigned, endian) {
11504
11520
  }
11505
11521
  }
11506
11522
  // Update the last chunk for the next iteration
11507
- lastChunk = combinedBuffer.subarray(-8 + 1);
11523
+ lastChunk = new Uint8Array(combinedBuffer.subarray(-8 + 1));
11508
11524
  ctx.offset += currentChunk.length;
11509
11525
  }
11510
11526
  return -1; // number not found
@@ -12031,16 +12047,16 @@ function wint64(ctx, value, unsigned, endian) {
12031
12047
  }
12032
12048
  else {
12033
12049
  if (unsigned == undefined || unsigned == false) {
12034
- data[(1 - i) * 4 + 0] = int32Array[i];
12035
- data[(1 - i) * 4 + 1] = (int32Array[i] >> 8);
12036
- data[(1 - i) * 4 + 2] = (int32Array[i] >> 16);
12037
- data[(1 - i) * 4 + 3] = (int32Array[i] >> 24);
12050
+ data[(1 - i) * 4 + 3] = int32Array[i];
12051
+ data[(1 - i) * 4 + 2] = (int32Array[i] >> 8);
12052
+ data[(1 - i) * 4 + 1] = (int32Array[i] >> 16);
12053
+ data[(1 - i) * 4 + 0] = (int32Array[i] >> 24);
12038
12054
  }
12039
12055
  else {
12040
- data[(1 - i) * 4 + 0] = int32Array[i] & 0xFF;
12041
- data[(1 - i) * 4 + 1] = (int32Array[i] >> 8) & 0xFF;
12042
- data[(1 - i) * 4 + 2] = (int32Array[i] >> 16) & 0xFF;
12043
- data[(1 - i) * 4 + 3] = (int32Array[i] >> 24) & 0xFF;
12056
+ data[(1 - i) * 4 + 3] = int32Array[i] & 0xFF;
12057
+ data[(1 - i) * 4 + 2] = (int32Array[i] >> 8) & 0xFF;
12058
+ data[(1 - i) * 4 + 1] = (int32Array[i] >> 16) & 0xFF;
12059
+ data[(1 - i) * 4 + 0] = (int32Array[i] >> 24) & 0xFF;
12044
12060
  }
12045
12061
  }
12046
12062
  }
@@ -12548,14 +12564,14 @@ class BiBaseStreamer {
12548
12564
  throw new Error('File read is outside of stream while in strict mode.');
12549
12565
  }
12550
12566
  }
12551
- var data = Buffer.alloc(length);
12567
+ var data = new Uint8Array(length);
12552
12568
  fs.readSync(this.fd, data, 0, data.length, start);
12553
- this.data = data;
12569
+ this.data = Buffer.from(data);
12554
12570
  if (consume) {
12555
12571
  this.offset = start + data.length;
12556
12572
  this.bitoffset = 0;
12557
12573
  }
12558
- return data;
12574
+ return this.data;
12559
12575
  }
12560
12576
  ;
12561
12577
  /**
@@ -12586,7 +12602,7 @@ class BiBaseStreamer {
12586
12602
  throw new Error('File write is outside of stream while in strict mode.');
12587
12603
  }
12588
12604
  }
12589
- const bytesWritten = fs.writeSync(this.fd, data, 0, data.length, start);
12605
+ const bytesWritten = fs.writeSync(this.fd, new Uint8Array(data), 0, data.length, start);
12590
12606
  this.updateSize();
12591
12607
  if (consume)
12592
12608
  this.offset = start + bytesWritten;
@@ -12601,7 +12617,7 @@ class BiBaseStreamer {
12601
12617
  */
12602
12618
  commit(consume = true) {
12603
12619
  this.open();
12604
- if (this.data instanceof Uint8Array) {
12620
+ if (!Buffer.isBuffer(this.data)) {
12605
12621
  var data = Buffer.from(this.data);
12606
12622
  return this.write(this.offset, data, consume);
12607
12623
  }