bireader 1.0.58 → 2.0.0

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.
@@ -1,6 +1,6 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.biwriter = exports.bireader = exports.hexdump = void 0;
3
+ exports.BiWriter = exports.BiReader = exports.biwriter = exports.bireader = exports.hexdump = void 0;
4
4
  function isBuffer(obj) {
5
5
  return buffcheck(obj);
6
6
  }
@@ -1141,7 +1141,7 @@ function whalffloat(_this, value, endian) {
1141
1141
  // Combine sign, exponent, and fraction bits into half float format
1142
1142
  let halfFloatBits = (signBit << 15) | (exponentBits << 10) | fractionBits;
1143
1143
  // Write bytes based on endianness
1144
- if ((endian = undefined ? endian : _this.endian) == "little") {
1144
+ if ((endian == undefined ? _this.endian : endian) == "little") {
1145
1145
  _this.data[_this.offset] = halfFloatBits & 0xFF;
1146
1146
  _this.data[_this.offset + 1] = (halfFloatBits >> 8) & 0xFF;
1147
1147
  }
@@ -1168,7 +1168,7 @@ function wint32(_this, value, unsigned, endian) {
1168
1168
  throw new Error('Value is out of range for the specified 32bit length.' + " min: " + minValue + " max: " + maxValue + " value: " + value);
1169
1169
  }
1170
1170
  }
1171
- if ((endian = undefined ? endian : _this.endian) == "little") {
1171
+ if ((endian == undefined ? _this.endian : endian) == "little") {
1172
1172
  _this.data[_this.offset] = (unsigned == undefined || unsigned == false) ? value : value & 0xFF;
1173
1173
  _this.data[_this.offset + 1] = (unsigned == undefined || unsigned == false) ? (value >> 8) : (value >> 8) & 0xFF;
1174
1174
  _this.data[_this.offset + 2] = (unsigned == undefined || unsigned == false) ? (value >> 16) : (value >> 16) & 0xFF;
@@ -1226,11 +1226,12 @@ function rfloat(_this, endian) {
1226
1226
  }
1227
1227
  function wfloat(_this, value, endian) {
1228
1228
  check_size(_this, 4, 0);
1229
- const MIN_POSITIVE_FLOAT32 = 1.17549435e-38;
1229
+ const MIN_POSITIVE_FLOAT32 = Number.MIN_VALUE;
1230
1230
  const MAX_POSITIVE_FLOAT32 = 3.4028235e+38;
1231
1231
  const MIN_NEGATIVE_FLOAT32 = -3.4028235e+38;
1232
- const MAX_NEGATIVE_FLOAT32 = -1.17549435e-38;
1233
- if (!((value === 0) || (value >= MIN_POSITIVE_FLOAT32 && value <= MAX_POSITIVE_FLOAT32) ||
1232
+ const MAX_NEGATIVE_FLOAT32 = -Number.MIN_VALUE;
1233
+ if (!((value === 0) ||
1234
+ (value >= MIN_POSITIVE_FLOAT32 && value <= MAX_POSITIVE_FLOAT32) ||
1234
1235
  (value >= MIN_NEGATIVE_FLOAT32 && value <= MAX_NEGATIVE_FLOAT32))) {
1235
1236
  _this.errorDump ? "[Error], hexdump:\n" + _this.hexdump() : "";
1236
1237
  throw new Error('Value is out of range for the specified float length.' + " min: " + MIN_NEGATIVE_FLOAT32 + " max: " + MAX_POSITIVE_FLOAT32 + " value: " + value);
@@ -1240,7 +1241,7 @@ function wfloat(_this, value, endian) {
1240
1241
  let intValue = dataView.getInt32(0, true);
1241
1242
  let shift = 0;
1242
1243
  for (let i = 0; i < 4; i++) {
1243
- if ((endian = undefined ? endian : _this.endian) == "little") {
1244
+ if ((endian == undefined ? _this.endian : endian) == "little") {
1244
1245
  _this.data[_this.offset + i] = (intValue >> shift) & 0xFF;
1245
1246
  }
1246
1247
  else {
@@ -1302,7 +1303,7 @@ function wint64(_this, value, unsigned, endian) {
1302
1303
  // Use two 32-bit views to write the Int64
1303
1304
  const int32Array = new Int32Array(bigIntArray.buffer);
1304
1305
  for (let i = 0; i < 2; i++) {
1305
- if ((endian = undefined ? endian : _this.endian) == "little") {
1306
+ if ((endian == undefined ? _this.endian : endian) == "little") {
1306
1307
  if (unsigned == undefined || unsigned == false) {
1307
1308
  _this.data[_this.offset + i * 4 + 0] = int32Array[i];
1308
1309
  _this.data[_this.offset + i * 4 + 1] = (int32Array[i] >> 8);
@@ -1337,8 +1338,8 @@ function wint64(_this, value, unsigned, endian) {
1337
1338
  function wdfloat(_this, value, endian) {
1338
1339
  check_size(_this, 8, 0);
1339
1340
  const MIN_POSITIVE_FLOAT64 = 2.2250738585072014e-308;
1340
- const MAX_POSITIVE_FLOAT64 = 1.7976931348623157e+308;
1341
- const MIN_NEGATIVE_FLOAT64 = -1.7976931348623157e+308;
1341
+ const MAX_POSITIVE_FLOAT64 = Number.MAX_VALUE;
1342
+ const MIN_NEGATIVE_FLOAT64 = -Number.MAX_VALUE;
1342
1343
  const MAX_NEGATIVE_FLOAT64 = -2.2250738585072014e-308;
1343
1344
  if (!((value === 0) ||
1344
1345
  (value >= MIN_POSITIVE_FLOAT64 && value <= MAX_POSITIVE_FLOAT64) ||
@@ -1351,7 +1352,7 @@ function wdfloat(_this, value, endian) {
1351
1352
  floatArray[0] = value;
1352
1353
  const bytes = new Uint8Array(intArray.buffer);
1353
1354
  for (let i = 0; i < 8; i++) {
1354
- if ((endian = undefined ? endian : _this.endian) == "little") {
1355
+ if ((endian == undefined ? _this.endian : endian) == "little") {
1355
1356
  _this.data[_this.offset + i] = bytes[i];
1356
1357
  }
1357
1358
  else {
@@ -1646,6 +1647,8 @@ function wstring(_this, string, options) {
1646
1647
  * @param {number} bitOffset - Bit offset 0-7 to start reader (default 0)
1647
1648
  * @param {string} endianness - Endianness ``big`` or ``little`` (default ``little``)
1648
1649
  * @param {boolean} strict - Strict mode: if true does not extend supplied array on outside write (default true)
1650
+ *
1651
+ * @deprecated Since version 1.0.59. Will be deleted in version 3.0. Use BiReader instead.
1649
1652
  */
1650
1653
  class bireader {
1651
1654
  isBufferOrUint8Array(obj) {
@@ -5026,6 +5029,27 @@ class bireader {
5026
5029
  writeByte(value, unsigned) {
5027
5030
  return wbyte(this, value, unsigned);
5028
5031
  }
5032
+ /**
5033
+ * Write multiple bytes.
5034
+ *
5035
+ * @param {number[]} values - array of values as int
5036
+ * @param {boolean} unsigned - if the value is unsigned
5037
+ */
5038
+ writeBytes(values, unsigned) {
5039
+ for (let i = 0; i < values.length; i++) {
5040
+ wbyte(this, values[i], unsigned);
5041
+ }
5042
+ }
5043
+ /**
5044
+ * Read multiple bytes.
5045
+ *
5046
+ * @param {number} amount - amount of bytes to read
5047
+ * @param {boolean} unsigned - if value is unsigned or not
5048
+ * @returns {number[]}
5049
+ */
5050
+ readBytes(amount, unsigned) {
5051
+ return Array.from({ length: amount }, () => rbyte(this, unsigned));
5052
+ }
5029
5053
  /**
5030
5054
  * Write unsigned byte.
5031
5055
  *
@@ -6401,6 +6425,8 @@ exports.bireader = bireader;
6401
6425
  * @param {number} bitOffset - Bit offset to start writer, 0-7
6402
6426
  * @param {string} endianness - Endianness ``big`` or ``little`` (default little)
6403
6427
  * @param {boolean} strict - Strict mode: if true does not extend supplied array on outside write (default false)
6428
+ *
6429
+ * @deprecated Since version 1.0.59. Will be deleted in version 3.0. Use BiWriter instead.
6404
6430
  */
6405
6431
  class biwriter {
6406
6432
  isBufferOrUint8Array(obj) {
@@ -10048,6 +10074,27 @@ class biwriter {
10048
10074
  writeByte(value, unsigned) {
10049
10075
  return wbyte(this, value, unsigned);
10050
10076
  }
10077
+ /**
10078
+ * Write multiple bytes.
10079
+ *
10080
+ * @param {number[]} values - array of values as int
10081
+ * @param {boolean} unsigned - if the value is unsigned
10082
+ */
10083
+ writeBytes(values, unsigned) {
10084
+ for (let i = 0; i < values.length; i++) {
10085
+ wbyte(this, values[i], unsigned);
10086
+ }
10087
+ }
10088
+ /**
10089
+ * Read multiple bytes.
10090
+ *
10091
+ * @param {number} amount - amount of bytes to read
10092
+ * @param {boolean} unsigned - if value is unsigned or not
10093
+ * @returns {number[]}
10094
+ */
10095
+ readBytes(amount, unsigned) {
10096
+ return Array.from({ length: amount }, () => rbyte(this, unsigned));
10097
+ }
10051
10098
  /**
10052
10099
  * Read byte.
10053
10100
  *
@@ -11394,4 +11441,8 @@ class biwriter {
11394
11441
  }
11395
11442
  }
11396
11443
  exports.biwriter = biwriter;
11444
+ var bireader_1 = require("./bireader");
11445
+ Object.defineProperty(exports, "BiReader", { enumerable: true, get: function () { return bireader_1.BiReader; } });
11446
+ var biwriter_1 = require("./biwriter");
11447
+ Object.defineProperty(exports, "BiWriter", { enumerable: true, get: function () { return biwriter_1.BiWriter; } });
11397
11448
  //# sourceMappingURL=index.js.map
package/package.json CHANGED
@@ -1,10 +1,9 @@
1
1
  {
2
2
  "name": "bireader",
3
- "version": "1.0.58",
3
+ "version": "2.0.0",
4
4
  "description": "Read and write data in binary",
5
- "module": "lib/esm/index.mjs",
6
- "main": "lib/cjs/index.cjs",
7
- "type": "module",
5
+ "module": "build/esm/index.js",
6
+ "main": "build/cjs/index.js",
8
7
  "files": [
9
8
  "lib"
10
9
  ],
@@ -14,19 +13,16 @@
14
13
  },
15
14
  "exports": {
16
15
  ".": {
17
- "import": "./lib/esm/index.mjs",
18
- "require": "./lib/cjs/index.cjs"
16
+ "import": "./build/esm/index.js",
17
+ "require": "./build/cjs/index.js"
19
18
  },
20
19
  "./*": "./*"
21
20
  },
22
21
  "scripts": {
23
- "clean": "rmdir /S /Q lib",
24
- "build": "npm run clean && npm run build:esm && npm run build:cjs && npm run movem && npm run movec",
25
- "build:esm": "tsc --module esnext --outDir lib/esm",
26
- "movem": "mjs.bat",
27
- "movec": "cjs.bat",
28
- "build:cjs": "tsc --module commonjs --outDir lib/cjs",
29
- "prepack": ""
22
+ "build": "npm run clean && npm run build:esm && npm run build:cjs",
23
+ "build:esm": "tsc --moduleResolution NodeNext --module NodeNext --outDir build/esm",
24
+ "build:cjs": "tsc --moduleResolution node --module commonjs --outDir build/cjs",
25
+ "clean": "rmdir /S /Q build"
30
26
  },
31
27
  "keywords": [
32
28
  "buffer",