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