bireader 1.0.27 → 1.0.29
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/cjs/index.js +15 -15
- package/lib/cjs/index.js.map +1 -1
- package/lib/esm/index.js.map +1 -1
- package/lib/esm/index.mjs +15 -15
- package/package.json +3 -4
- package/src/index.ts +15 -15
package/lib/esm/index.mjs
CHANGED
|
@@ -45,7 +45,7 @@ export function checkSize(_this, write_bytes, write_bit, offset) {
|
|
|
45
45
|
}
|
|
46
46
|
export function skip(_this, bytes, bits) {
|
|
47
47
|
const new_size = (((bytes || 0) + _this.offset) + Math.ceil((_this.bitoffset + (bits || 0)) / 8));
|
|
48
|
-
|
|
48
|
+
check_size(_this, bytes || 0, bits || 0);
|
|
49
49
|
if (new_size > _this.size) {
|
|
50
50
|
if (_this.strict == false) {
|
|
51
51
|
_this.extendArray(new_size - _this.size);
|
|
@@ -740,7 +740,7 @@ export function rbit(_this, bits, unsigned, endian) {
|
|
|
740
740
|
return value;
|
|
741
741
|
}
|
|
742
742
|
export function wbyte(_this, value, unsigned) {
|
|
743
|
-
|
|
743
|
+
check_size(_this, 1, 0);
|
|
744
744
|
if (unsigned == true) {
|
|
745
745
|
if (value < 0 || value > 255) {
|
|
746
746
|
_this.errorDump ? "[Error], hexdump:\n" + _this.hexdump() : "";
|
|
@@ -760,7 +760,7 @@ export function wbyte(_this, value, unsigned) {
|
|
|
760
760
|
_this.bitoffset = 0;
|
|
761
761
|
}
|
|
762
762
|
export function rbyte(_this, unsigned) {
|
|
763
|
-
|
|
763
|
+
check_size(_this, 1);
|
|
764
764
|
var read = _this.data[_this.offset];
|
|
765
765
|
_this.offset += 1;
|
|
766
766
|
_this.bitoffset = 0;
|
|
@@ -772,7 +772,7 @@ export function rbyte(_this, unsigned) {
|
|
|
772
772
|
}
|
|
773
773
|
}
|
|
774
774
|
export function wint16(_this, value, unsigned, endian) {
|
|
775
|
-
|
|
775
|
+
check_size(_this, 2, 0);
|
|
776
776
|
if (unsigned == true) {
|
|
777
777
|
if (value < 0 || value > 65535) {
|
|
778
778
|
_this.errorDump ? "[Error], hexdump:\n" + _this.hexdump() : "";
|
|
@@ -799,7 +799,7 @@ export function wint16(_this, value, unsigned, endian) {
|
|
|
799
799
|
_this.bitoffset = 0;
|
|
800
800
|
}
|
|
801
801
|
export function rint16(_this, unsigned, endian) {
|
|
802
|
-
|
|
802
|
+
check_size(_this, 2);
|
|
803
803
|
var read;
|
|
804
804
|
if ((endian != undefined ? endian : _this.endian) == "little") {
|
|
805
805
|
read = (_this.data[_this.offset + 1] << 8) | _this.data[_this.offset];
|
|
@@ -846,7 +846,7 @@ export function rhalffloat(_this, endian) {
|
|
|
846
846
|
return floatValue;
|
|
847
847
|
}
|
|
848
848
|
export function whalffloat(_this, value, endian) {
|
|
849
|
-
|
|
849
|
+
check_size(_this, 2, 0);
|
|
850
850
|
const maxValue = 65504;
|
|
851
851
|
const minValue = 5.96e-08;
|
|
852
852
|
if (value < minValue || value > maxValue) {
|
|
@@ -889,7 +889,7 @@ export function whalffloat(_this, value, endian) {
|
|
|
889
889
|
_this.bitoffset = 0;
|
|
890
890
|
}
|
|
891
891
|
export function wint32(_this, value, unsigned, endian) {
|
|
892
|
-
|
|
892
|
+
check_size(_this, 4, 0);
|
|
893
893
|
if (unsigned == true) {
|
|
894
894
|
if (value < 0 || value > 4294967295) {
|
|
895
895
|
_this.errorDump ? "[Error], hexdump:\n" + _this.hexdump() : "";
|
|
@@ -920,7 +920,7 @@ export function wint32(_this, value, unsigned, endian) {
|
|
|
920
920
|
_this.bitoffset = 0;
|
|
921
921
|
}
|
|
922
922
|
export function rint32(_this, unsigned, endian) {
|
|
923
|
-
|
|
923
|
+
check_size(_this, 4);
|
|
924
924
|
var read;
|
|
925
925
|
if ((endian != undefined ? endian : _this.endian) == "little") {
|
|
926
926
|
read = ((_this.data[_this.offset + 3] << 24) | (_this.data[_this.offset + 2] << 16) | (_this.data[_this.offset + 1] << 8) | _this.data[_this.offset]);
|
|
@@ -961,7 +961,7 @@ export function rfloat(_this, endian) {
|
|
|
961
961
|
return floatValue;
|
|
962
962
|
}
|
|
963
963
|
export function wfloat(_this, value, endian) {
|
|
964
|
-
|
|
964
|
+
check_size(_this, 4, 0);
|
|
965
965
|
const maxValue = 3.402823466e+38;
|
|
966
966
|
const minValue = 1.175494351e-38;
|
|
967
967
|
if (value < minValue || value > maxValue) {
|
|
@@ -983,7 +983,7 @@ export function wfloat(_this, value, endian) {
|
|
|
983
983
|
_this.bitoffset = 0;
|
|
984
984
|
}
|
|
985
985
|
export function rint64(_this, unsigned, endian) {
|
|
986
|
-
|
|
986
|
+
check_size(_this, 8);
|
|
987
987
|
// Convert the byte array to a BigInt
|
|
988
988
|
let value = BigInt(0);
|
|
989
989
|
if ((endian == undefined ? _this.endian : endian) == "little") {
|
|
@@ -1013,7 +1013,7 @@ export function rint64(_this, unsigned, endian) {
|
|
|
1013
1013
|
return value;
|
|
1014
1014
|
}
|
|
1015
1015
|
export function wint64(_this, value, unsigned, endian) {
|
|
1016
|
-
|
|
1016
|
+
check_size(_this, 8, 0);
|
|
1017
1017
|
if (unsigned == true) {
|
|
1018
1018
|
if (value < 0 || value > Math.pow(2, 64) - 1) {
|
|
1019
1019
|
_this.errorDump ? "[Error], hexdump:\n" + _this.hexdump() : "";
|
|
@@ -1067,7 +1067,7 @@ export function wint64(_this, value, unsigned, endian) {
|
|
|
1067
1067
|
_this.bitoffset = 0;
|
|
1068
1068
|
}
|
|
1069
1069
|
export function wdfloat(_this, value, endian) {
|
|
1070
|
-
|
|
1070
|
+
check_size(_this, 8, 0);
|
|
1071
1071
|
const maxValue = 1.7976931348623158e308;
|
|
1072
1072
|
const minValue = 2.2250738585072014e-308;
|
|
1073
1073
|
if (value < minValue || value > maxValue) {
|
|
@@ -1128,7 +1128,7 @@ export function rstring(_this, options) {
|
|
|
1128
1128
|
var endian = options && options.endian || _this.endian;
|
|
1129
1129
|
var terminate = terminateValue;
|
|
1130
1130
|
if (length != undefined) {
|
|
1131
|
-
|
|
1131
|
+
check_size(_this, length);
|
|
1132
1132
|
}
|
|
1133
1133
|
if (typeof terminateValue == "number") {
|
|
1134
1134
|
terminate = terminateValue & 0xFF;
|
|
@@ -1266,7 +1266,7 @@ export function wstring(_this, string, options) {
|
|
|
1266
1266
|
if (stringType == 'utf-16') {
|
|
1267
1267
|
totalLength = (length || (encodedString.length * 2)) + (terminateValue != undefined ? 2 : 0);
|
|
1268
1268
|
}
|
|
1269
|
-
|
|
1269
|
+
check_size(_this, totalLength, 0);
|
|
1270
1270
|
// Write the string bytes to the Uint8Array
|
|
1271
1271
|
for (let i = 0; i < encodedString.length; i++) {
|
|
1272
1272
|
if (stringType === 'utf-16') {
|
|
@@ -1332,7 +1332,7 @@ export function wstring(_this, string, options) {
|
|
|
1332
1332
|
if (stringType == 'wide-pascal') {
|
|
1333
1333
|
totalLength = (length || (encodedString.length * 2)) + lengthWriteSize;
|
|
1334
1334
|
}
|
|
1335
|
-
|
|
1335
|
+
check_size(_this, totalLength, 0);
|
|
1336
1336
|
if (lengthWriteSize == 1) {
|
|
1337
1337
|
_this.writeUByte(maxBytes);
|
|
1338
1338
|
}
|
package/package.json
CHANGED
|
@@ -1,10 +1,9 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "bireader",
|
|
3
|
-
"version": "1.0.
|
|
3
|
+
"version": "1.0.29",
|
|
4
4
|
"description": "Read and write data in binary",
|
|
5
|
-
"
|
|
6
|
-
"
|
|
7
|
-
"main": "./lib/cjs/index.js",
|
|
5
|
+
"module": "lib/esm/index.mjs",
|
|
6
|
+
"main": "lib/cjs/index.js",
|
|
8
7
|
"directories": {
|
|
9
8
|
"lib": "src"
|
|
10
9
|
},
|
package/src/index.ts
CHANGED
|
@@ -49,7 +49,7 @@ export function checkSize(_this: any, write_bytes:number, write_bit?:number, off
|
|
|
49
49
|
|
|
50
50
|
export function skip(_this: any, bytes: number, bits?: number): void{
|
|
51
51
|
const new_size = (((bytes || 0) + _this.offset) + Math.ceil((_this.bitoffset + (bits||0)) /8) )
|
|
52
|
-
|
|
52
|
+
check_size(_this, bytes || 0, bits || 0)
|
|
53
53
|
if(new_size > _this.size){
|
|
54
54
|
if( _this.strict == false){
|
|
55
55
|
_this.extendArray(new_size - _this.size)
|
|
@@ -736,7 +736,7 @@ export function rbit(_this:any,bits?: number, unsigned?: boolean, endian?: strin
|
|
|
736
736
|
}
|
|
737
737
|
|
|
738
738
|
export function wbyte(_this:any,value: number, unsigned?: boolean): void{
|
|
739
|
-
|
|
739
|
+
check_size(_this,1,0)
|
|
740
740
|
if (unsigned == true) {
|
|
741
741
|
if (value< 0 || value > 255) {
|
|
742
742
|
_this.errorDump ? "[Error], hexdump:\n" + _this.hexdump() : ""
|
|
@@ -756,7 +756,7 @@ export function wbyte(_this:any,value: number, unsigned?: boolean): void{
|
|
|
756
756
|
}
|
|
757
757
|
|
|
758
758
|
export function rbyte(_this:any,unsigned?: boolean): number{
|
|
759
|
-
|
|
759
|
+
check_size(_this,1)
|
|
760
760
|
var read = <unknown> _this.data[_this.offset] as number
|
|
761
761
|
_this.offset += 1
|
|
762
762
|
_this.bitoffset = 0
|
|
@@ -768,7 +768,7 @@ export function rbyte(_this:any,unsigned?: boolean): number{
|
|
|
768
768
|
}
|
|
769
769
|
|
|
770
770
|
export function wint16(_this:any, value: number, unsigned?: boolean, endian?: string): void {
|
|
771
|
-
|
|
771
|
+
check_size(_this,2,0)
|
|
772
772
|
if (unsigned == true) {
|
|
773
773
|
if (value< 0 || value > 65535) {
|
|
774
774
|
_this.errorDump ? "[Error], hexdump:\n" + _this.hexdump() : ""
|
|
@@ -794,7 +794,7 @@ export function wint16(_this:any, value: number, unsigned?: boolean, endian?: st
|
|
|
794
794
|
}
|
|
795
795
|
|
|
796
796
|
export function rint16(_this:any,unsigned?: boolean, endian?: string): number{
|
|
797
|
-
|
|
797
|
+
check_size(_this,2)
|
|
798
798
|
var read: number;
|
|
799
799
|
if((endian != undefined ? endian : _this.endian) == "little"){
|
|
800
800
|
read = ((<unknown>_this.data[_this.offset + 1] as number & 0xFFFF) << 8) | (<unknown>_this.data[_this.offset] as number & 0xFFFF);
|
|
@@ -841,7 +841,7 @@ export function rhalffloat(_this:any,endian?: string): number{
|
|
|
841
841
|
}
|
|
842
842
|
|
|
843
843
|
export function whalffloat(_this:any,value: number, endian?: string): void {
|
|
844
|
-
|
|
844
|
+
check_size(_this,2,0)
|
|
845
845
|
const maxValue = 65504;
|
|
846
846
|
const minValue = 5.96e-08;
|
|
847
847
|
if(value < minValue || value > maxValue){
|
|
@@ -887,7 +887,7 @@ export function whalffloat(_this:any,value: number, endian?: string): void {
|
|
|
887
887
|
}
|
|
888
888
|
|
|
889
889
|
export function wint32(_this:any, value: number, unsigned?: boolean, endian?: string): void {
|
|
890
|
-
|
|
890
|
+
check_size(_this,4,0)
|
|
891
891
|
if (unsigned == true) {
|
|
892
892
|
if (value < 0 || value > 4294967295) {
|
|
893
893
|
_this.errorDump ? "[Error], hexdump:\n" + _this.hexdump() : ""
|
|
@@ -917,7 +917,7 @@ export function wint32(_this:any, value: number, unsigned?: boolean, endian?: st
|
|
|
917
917
|
}
|
|
918
918
|
|
|
919
919
|
export function rint32(_this:any,unsigned?: boolean, endian?: string): number{
|
|
920
|
-
|
|
920
|
+
check_size(_this,4)
|
|
921
921
|
var read: number;
|
|
922
922
|
if((endian != undefined ? endian : _this.endian) == "little"){
|
|
923
923
|
read = (((<unknown>_this.data[_this.offset + 3] as number & 0xFF)<< 24) | ((<unknown>_this.data[_this.offset + 2] as number & 0xFF) << 16) | ((<unknown>_this.data[_this.offset + 1] as number & 0xFF) << 8) | (<unknown>_this.data[_this.offset] as number & 0xFF))
|
|
@@ -961,7 +961,7 @@ export function rfloat(_this:any, endian?: string): number{
|
|
|
961
961
|
}
|
|
962
962
|
|
|
963
963
|
export function wfloat(_this:any, value: number, endian?: string): void{
|
|
964
|
-
|
|
964
|
+
check_size(_this,4,0)
|
|
965
965
|
const maxValue = 3.402823466e+38
|
|
966
966
|
const minValue = 1.175494351e-38
|
|
967
967
|
if(value < minValue || value > maxValue){
|
|
@@ -985,7 +985,7 @@ export function wfloat(_this:any, value: number, endian?: string): void{
|
|
|
985
985
|
}
|
|
986
986
|
|
|
987
987
|
export function rint64(_this:any, unsigned?: boolean, endian?: string): bigint {
|
|
988
|
-
|
|
988
|
+
check_size(_this,8)
|
|
989
989
|
|
|
990
990
|
// Convert the byte array to a BigInt
|
|
991
991
|
let value: bigint = BigInt(0);
|
|
@@ -1016,7 +1016,7 @@ export function rint64(_this:any, unsigned?: boolean, endian?: string): bigint {
|
|
|
1016
1016
|
}
|
|
1017
1017
|
|
|
1018
1018
|
export function wint64(_this:any, value: number, unsigned?: boolean, endian?: string): void {
|
|
1019
|
-
|
|
1019
|
+
check_size(_this,8,0)
|
|
1020
1020
|
if (unsigned == true) {
|
|
1021
1021
|
if (value < 0 || value > Math.pow(2, 64) - 1) {
|
|
1022
1022
|
_this.errorDump ? "[Error], hexdump:\n" + _this.hexdump() : ""
|
|
@@ -1070,7 +1070,7 @@ export function wint64(_this:any, value: number, unsigned?: boolean, endian?: st
|
|
|
1070
1070
|
}
|
|
1071
1071
|
|
|
1072
1072
|
export function wdfloat(_this:any, value: number, endian?: string): void {
|
|
1073
|
-
|
|
1073
|
+
check_size(_this,8,0)
|
|
1074
1074
|
const maxValue = 1.7976931348623158e308;
|
|
1075
1075
|
const minValue = 2.2250738585072014e-308;
|
|
1076
1076
|
if(value < minValue || value > maxValue){
|
|
@@ -1147,7 +1147,7 @@ export function rstring(_this:any, options?: {
|
|
|
1147
1147
|
var terminate = terminateValue
|
|
1148
1148
|
|
|
1149
1149
|
if(length != undefined){
|
|
1150
|
-
|
|
1150
|
+
check_size(_this,length)
|
|
1151
1151
|
}
|
|
1152
1152
|
|
|
1153
1153
|
if(typeof terminateValue == "number"){
|
|
@@ -1304,7 +1304,7 @@ export function wstring(_this:any, string: string, options?: {
|
|
|
1304
1304
|
totalLength = (length || (encodedString.length*2)) + (terminateValue != undefined ? 2 : 0)
|
|
1305
1305
|
}
|
|
1306
1306
|
|
|
1307
|
-
|
|
1307
|
+
check_size(_this,totalLength, 0)
|
|
1308
1308
|
|
|
1309
1309
|
// Write the string bytes to the Uint8Array
|
|
1310
1310
|
for (let i = 0; i < encodedString.length; i++) {
|
|
@@ -1374,7 +1374,7 @@ export function wstring(_this:any, string: string, options?: {
|
|
|
1374
1374
|
totalLength = (length || (encodedString.length*2)) + lengthWriteSize
|
|
1375
1375
|
}
|
|
1376
1376
|
|
|
1377
|
-
|
|
1377
|
+
check_size(_this,totalLength, 0)
|
|
1378
1378
|
|
|
1379
1379
|
if(lengthWriteSize == 1){
|
|
1380
1380
|
_this.writeUByte(maxBytes);
|