bireader 1.0.1 → 1.0.2

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/README.md CHANGED
@@ -8,7 +8,7 @@ Supported data types are:
8
8
  - [Bytes](#byte) ([u]int8, byte) 8 bit signed or unsigned value
9
9
  - [Shorts](#short) ([u]int16, word, short{le|be}) 16 bit signed or unsigned value in big or little endian order
10
10
  - [Half Floats](#half-float) (halffloat, half{le|be}) 16 bit decimal value in big or little endian order
11
- - [Integers](#integer) ([u]int32, int, double{le|be}) 32 bit signed or unsigned value in big or little endian order
11
+ - [Integers](#integer) ([u]int32, long, int, double{le|be}) 32 bit signed or unsigned value in big or little endian order
12
12
  - [Floats](#float) (float{le|be}) 32 bit decimal value in big or little endian
13
13
  - [Quadwords](#quadword) ([u]int64, quad, bigint{le|be}) 64 bit signed or unsigned in big or little endian
14
14
  - [Double Floats](#double-float) (doublefloat, dfloat{le|be}) 64 bit decimal value in big or little endian
@@ -341,7 +341,7 @@ Parse value as a half float (aka half). Can be in little or big endian order (``
341
341
 
342
342
  ## Integer
343
343
 
344
- Parse value as a int32 (aka int or double). Can be signed or unsigned (with a ``u`` at the start) and in little or big endian order (``be`` or ``le`` at the end).
344
+ Parse value as a int32 (aka int, long or double). Can be signed or unsigned (with a ``u`` at the start) and in little or big endian order (``be`` or ``le`` at the end).
345
345
 
346
346
  <table>
347
347
  <thead>
@@ -363,12 +363,12 @@ Parse value as a int32 (aka int or double). Can be signed or unsigned (with a ``
363
363
  </tr>
364
364
  <tr>
365
365
  <td align="center"><b>Presets (reader)</b></td>
366
- <td>[u]{int32|int|double}{be|le}(*unsigned, *endian)</td>
366
+ <td>[u]{int32|long|int|double}{be|le}(*unsigned, *endian)</td>
367
367
  <td>If value is unsigned, little or big endian.<br>*Note: functions without the starting letter <u>u</u> can still be called unsigned when <b>true</b> is the <i>first</i> augment, and functions without ending letters <u>be</u> or <u>le</u> can still be called the endian in the <i>second</i> augment (does not overwite set endian).</td>
368
368
  </tr>
369
369
  <tr>
370
370
  <td align="center"><b>Presets (writer)</b></td>
371
- <td>[u]{int32|int|double}{be|le}(<b>value</b>, offsetBytes, *unsigned, *endian)</td>
371
+ <td>[u]{int32|long|int|double}{be|le}(<b>value</b>, offsetBytes, *unsigned, *endian)</td>
372
372
  <td><b>value to write</b>, byte offset from current position, if value is unsigned, little or big endian<br>*Note: functions without the starting letter <u>u</u> can still be called unsigned when <b>true</b> is the <i>third</i> augment, and functions without ending letters <u>be</u> or <u>le</u> can still be called the endian in the <i>fourth</i> augment (does not overwite set endian).</td>
373
373
  </tr>
374
374
  </tbody>
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "bireader",
3
- "version": "1.0.1",
3
+ "version": "1.0.2",
4
4
  "description": "Read and write data in binary",
5
5
  "main": "index.js",
6
6
  "directories": {
package/src/reader.js CHANGED
@@ -2521,6 +2521,17 @@ class bireader {
2521
2521
  /**
2522
2522
  * Read unsigned short
2523
2523
  *
2524
+ * @param {string} endian - ```big``` or ```little```
2525
+ *
2526
+ * @returns number
2527
+ */
2528
+ readUInt16 = this.uint16 = this.ushort = this.uword = function(endian){
2529
+ return this.readInt16(true, endian)
2530
+ }
2531
+
2532
+ /**
2533
+ * Read unsigned short in little endian
2534
+ *
2524
2535
  * @returns number
2525
2536
  */
2526
2537
  readUInt16LE = this.uint16le = this.ushortle = this.uwordle = function(){
@@ -2528,7 +2539,7 @@ class bireader {
2528
2539
  }
2529
2540
 
2530
2541
  /**
2531
- * Read signed short
2542
+ * Read signed short in little endian
2532
2543
  *
2533
2544
  * @returns number
2534
2545
  */
@@ -2537,7 +2548,7 @@ class bireader {
2537
2548
  }
2538
2549
 
2539
2550
  /**
2540
- * Read unsigned short
2551
+ * Read unsigned short in big endian
2541
2552
  *
2542
2553
  * @returns number
2543
2554
  */
@@ -2546,7 +2557,7 @@ class bireader {
2546
2557
  }
2547
2558
 
2548
2559
  /**
2549
- * Read signed short
2560
+ * Read signed short in big endian
2550
2561
  *
2551
2562
  * @returns number
2552
2563
  */
@@ -2628,7 +2639,7 @@ class bireader {
2628
2639
  * @param {string} endian - ```big``` or ```little```
2629
2640
  * @returns number
2630
2641
  */
2631
- readInt32 = this.int = this.double = this.int32 = function(unsigned, endian){
2642
+ readInt32 = this.int = this.double = this.int32 = this.long = function(unsigned, endian){
2632
2643
  this.#check_size(4)
2633
2644
  var read;
2634
2645
  if((endian != undefined ? endian : this.endian) == "little"){
@@ -2649,7 +2660,7 @@ class bireader {
2649
2660
  *
2650
2661
  * @returns number
2651
2662
  */
2652
- readUInt = this.uint = this.udouble = this.uint32 = function(){
2663
+ readUInt = this.uint = this.udouble = this.uint32 = this.ulong = function(){
2653
2664
  return this.readInt32(true)
2654
2665
  }
2655
2666
 
@@ -2658,7 +2669,7 @@ class bireader {
2658
2669
  *
2659
2670
  * @returns number
2660
2671
  */
2661
- readInt32BE = this.intbe = this.doublebe = this.int32be = function(){
2672
+ readInt32BE = this.intbe = this.doublebe = this.int32be = this.longbe = function(){
2662
2673
  return this.readInt32(false, "big")
2663
2674
  }
2664
2675
 
@@ -2667,7 +2678,7 @@ class bireader {
2667
2678
  *
2668
2679
  * @returns number
2669
2680
  */
2670
- readUInt32BE = this.uintbe = this.udoublebe = this.uint32be = function(){
2681
+ readUInt32BE = this.uintbe = this.udoublebe = this.uint32be = this.ulongbe = function(){
2671
2682
  return this.readInt32(true, "big")
2672
2683
  }
2673
2684
 
@@ -2676,7 +2687,7 @@ class bireader {
2676
2687
  *
2677
2688
  * @returns number
2678
2689
  */
2679
- readInt32LE = this.intle = this.doublele = this.int32le = function(){
2690
+ readInt32LE = this.intle = this.doublele = this.int32le = this.longle = function(){
2680
2691
  return this.readInt32(false, "little")
2681
2692
  }
2682
2693
 
@@ -2685,7 +2696,7 @@ class bireader {
2685
2696
  *
2686
2697
  * @returns number
2687
2698
  */
2688
- readUInt32LE = this.uintle = this.udoublele = this.uint32le = function(){
2699
+ readUInt32LE = this.uintle = this.udoublele = this.uint32le = this.ulongle = function(){
2689
2700
  return this.readInt32(true, "little")
2690
2701
  }
2691
2702
 
@@ -2966,7 +2977,15 @@ class bireader {
2966
2977
  terminate = 0
2967
2978
  }
2968
2979
 
2969
- while (this.offset < this.data.length) {
2980
+ var read_length = 0;
2981
+
2982
+ if(length != undefined){
2983
+ read_length = length
2984
+ } else {
2985
+ read_length = this.data.length - this.offset
2986
+ }
2987
+
2988
+ for (let i = 0; i < read_length; i++) {
2970
2989
  if (stringType === 'utf-8') {
2971
2990
  var read = this.readUByte();
2972
2991
  if(read == terminate){
package/src/writer.js CHANGED
@@ -7,7 +7,7 @@
7
7
  * @param {string} endianness - endianness ``big`` or ``little`` (default little)
8
8
  * @param {boolean} strict - strict mode: if true does not extend supplied array on outside write (default false)
9
9
  */
10
- class biwriter {
10
+ class biwriter {
11
11
  endian = "little";
12
12
  offset = 0;
13
13
  bitoffset = 0;
@@ -3305,7 +3305,7 @@
3305
3305
  * @param {boolean} unsigned - if the value is unsigned
3306
3306
  * @param {string} endian - ``big`` or ``little`
3307
3307
  */
3308
- writeInt32 = this.int = this.int32 = this.double = function(value, offset, unsigned, endian) {
3308
+ writeInt32 = this.int = this.int32 = this.double = this.long = function(value, offset, unsigned, endian) {
3309
3309
  this.#check_size(4,0,offset)
3310
3310
  if (unsigned == true) {
3311
3311
  if (value < 0 || value > 4294967295) {
@@ -3339,7 +3339,7 @@
3339
3339
  * @param {number} offset - byte offset (default last write position)
3340
3340
  * @param {string} endian - ``big`` or ``little`
3341
3341
  */
3342
- writeUInt32 = this.uint32 = this.uint = this.udouble= function(value, offset, endian) {
3342
+ writeUInt32 = this.uint32 = this.uint = this.udouble = this.ulong = function(value, offset, endian) {
3343
3343
  return this.writeInt32(value, offset, true, endian)
3344
3344
  }
3345
3345
 
@@ -3349,7 +3349,7 @@
3349
3349
  * @param {number} value - value as int
3350
3350
  * @param {number} offset - byte offset (default last write position)
3351
3351
  */
3352
- writeInt32LE = this.int32le = this.intle = this.doublele = function(value, offset) {
3352
+ writeInt32LE = this.int32le = this.intle = this.doublele = this.longle = function(value, offset) {
3353
3353
  return this.writeInt32(value, offset, false, "little")
3354
3354
  }
3355
3355
 
@@ -3359,7 +3359,7 @@
3359
3359
  * @param {number} value - value as int
3360
3360
  * @param {number} offset - byte offset (default last write position)
3361
3361
  */
3362
- writeUInt32LE = this.uint32le = this.uintle = this.udoublele = function(value, offset) {
3362
+ writeUInt32LE = this.uint32le = this.uintle = this.udoublele = this.ulongle = function(value, offset) {
3363
3363
  return this.writeInt32(value, offset, true, "little")
3364
3364
  }
3365
3365
 
@@ -3369,7 +3369,7 @@
3369
3369
  * @param {number} value - value as int
3370
3370
  * @param {number} offset - byte offset (default last write position)
3371
3371
  */
3372
- writeInt32BE = this.int32be = this.int32be = this.doublebe = function(value, offset) {
3372
+ writeInt32BE = this.int32be = this.int32be = this.doublebe = this.longbe = function(value, offset) {
3373
3373
  return this.writeInt32(value, offset, false, "big")
3374
3374
  }
3375
3375
 
@@ -3379,7 +3379,7 @@
3379
3379
  * @param {number} value - value as int
3380
3380
  * @param {number} offset - byte offset (default last write position)
3381
3381
  */
3382
- writeUInt32BE = this.uint32be = this.uint32be = this.udoublebe = function(value, offset) {
3382
+ writeUInt32BE = this.uint32be = this.uint32be = this.udoublebe = this.ulongbe = function(value, offset) {
3383
3383
  return this.writeInt32(value, offset, true, "big")
3384
3384
  }
3385
3385