bireader 1.0.0 → 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.
Files changed (4) hide show
  1. package/README.md +561 -1
  2. package/package.json +2 -1
  3. package/src/reader.js +3002 -574
  4. package/src/writer.js +3871 -330
package/src/reader.js CHANGED
@@ -1,13 +1,12 @@
1
- /**
2
- *
3
- * byte reader, includes bitfields and strings
4
- *
5
- * @param {Buffer|Uint8Array} data - ```Buffer``` or ```Uint8Array```
6
- * @param {number} byteoffset - byte offset to start reader, default is 0
7
- * @param {number} bitoffset - bit offset to start reader, 0-7
8
- * @param endianness - endianness ```big``` or ```little``` (default ```little```)
9
- * @returns ```number``` or ```string```
10
- */
1
+ /**
2
+ *
3
+ * byte reader, includes bitfields and strings
4
+ *
5
+ * @param {Buffer|Uint8Array} data - ```Buffer``` or ```Uint8Array```
6
+ * @param {number} byteOffset - byte offset to start reader, default is 0
7
+ * @param {number} bitOffset - bit offset to start reader, 0-7
8
+ * @param {string} endianness - endianness ```big``` or ```little``` (default ```little```)
9
+ */
11
10
  class bireader {
12
11
  endian = "little";
13
12
  offset = 0;
@@ -15,823 +14,2858 @@ class bireader {
15
14
  size = 0
16
15
  data;
17
16
 
18
- #check_size = function(read_size){
19
- if(this.bitoffset != 0){
20
- //droped bits
21
- const new_off = Math.ceil(this.bitoffset / 8)
22
- this.offset = this.offset + new_off
23
- }
24
- if((this.offset + read_size) > this.size){
17
+ #check_size = function(read_size, read_bits){
18
+ const new_off = this.offset + (read_size||0) + Math.ceil((this.bitoffset + (read_bits||0) )/ 8)
19
+ if(new_off > this.size){
25
20
  throw new Error(`Reader reached end of data.`);
26
21
  }
27
22
  }
28
23
 
29
24
  /**
30
- *
31
- * byte reader, includes bitfields and strings
32
- *
33
- * @param {Buffer|Uint8Array} data - ```Buffer``` or ```Uint8Array```
34
- * @param {number} byteoffset - byte offset to start reader, default is 0
35
- * @param {number} bitoffset - bit offset to start reader, 0-7
36
- * @param endianness - endianness ```big``` or ```little``` (default ```little```)
37
- * @returns ```number``` or ```string```
38
- */
39
- constructor(data, byteoffset, bitoffset, endianness) {
25
+ *
26
+ * byte reader, includes bitfields and strings
27
+ *
28
+ * @param {Buffer|Uint8Array} data - ```Buffer``` or ```Uint8Array```
29
+ * @param {number} byteOffset - byte offset to start reader, default is 0
30
+ * @param {number} bitOffset - bit offset to start reader, 0-7
31
+ * @param {string} endianness - endianness ```big``` or ```little``` (default ```little```)
32
+ */
33
+ constructor(data, byteOffset, bitOffset, endianness) {
40
34
  if(endianness != undefined && typeof endianness != "string"){
41
- throw Error("endianness must be big or little")
35
+ throw new Error("Endian must be big or little")
42
36
  }
43
37
  if(endianness != undefined && !(endianness == "big" || endianness == "little")){
44
- throw Error("byteorder must be big or little")
38
+ throw new Error("Byte order must be big or little")
45
39
  }
46
40
  this.endian = endianness || "little"
47
41
 
48
- if(byteoffset != undefined ){
49
- if(typeof byteoffset == "number"){
50
- this.offset = Math.round(byteoffset) || 0
42
+ if(byteOffset != undefined ){
43
+ if(typeof byteOffset == "number"){
44
+ this.offset = Math.round(byteOffset) || 0
51
45
  } else {
52
- throw Error("Byteoffset must be number")
46
+ throw new Error("Byte offset must be number")
53
47
  }
54
48
  }
55
- if(bitoffset!= undefined){
56
- this.bitoffset = (bitoffset % 8)
49
+ if(bitOffset!= undefined){
50
+ this.bitoffset = (bitOffset % 8)
57
51
  }
58
52
  if(data == undefined){
59
- throw Error("Data required")
53
+ throw new Error("Data required")
60
54
  } else {
61
- this.size = data.length + ((bitoffset || 0) % 8)
55
+ this.size = data.length + ((bitOffset || 0) % 8)
62
56
  this.data = data
63
57
  }
64
58
  }
65
59
 
66
- endianness = function(order){
67
- if(order == undefined || typeof order != "string"){
68
- throw Error("endianness must be big or little")
60
+ /**
61
+ *
62
+ * Change endian, defaults to little
63
+ *
64
+ * Can be changed at any time, doesn't loose position
65
+ *
66
+ * @param {string} endian - endianness ```big``` or ```little```
67
+ */
68
+ endianness = function(endian){
69
+ if(endian == undefined || typeof endian != "string"){
70
+ throw new Error("Endian must be big or little")
69
71
  }
70
- if(order != undefined && !(order == "big" || order == "little")){
71
- throw Error("byteorder must be big or little")
72
+ if(endian != undefined && !(endian == "big" || endian == "little")){
73
+ throw new Error("Endian must be big or little")
72
74
  }
73
- this.endian = order
75
+ this.endian = endian
74
76
  }
75
77
 
76
- /**
77
- *
78
- * @param {number} offset - bytes to skip
79
- */
80
- seek = function(offset){
81
- this.#check_size(offset)
82
- this.offset += offset
78
+ /**
79
+ *Sets endian to big
80
+ */
81
+ bigEndian = this.big = this.be = function(){
82
+ this.endianness("big")
83
83
  }
84
84
 
85
85
  /**
86
- *
87
- * @param {number} offset - byte to jump to
88
- */
89
- goto = function(loc){
90
- if(loc > this.size){
91
- throw Error("goto outside of size of data")
92
- }
93
- this.offset = loc
86
+ * Sets endian to little
87
+ */
88
+ littleEndian = this.little = this.le = function(){
89
+ this.endianness("little")
94
90
  }
95
91
 
96
92
  /**
97
- *
98
- * bit field reader
99
- *
100
- * Note: When returning to a byte read, remaining bits are dropped
101
- *
102
- * @param {number} numBitsToRead - bits to read
103
- * @returns number
104
- */
105
- readBit = function(numBitsToRead, endian){
106
- if(numBitsToRead == undefined || typeof numBitsToRead != "number"){
107
- throw Error("Enter number of bits to read")
108
- }
109
- const size_needed = ((((numBitsToRead-1) + this.bitoffset) / 8) + this.offset)
110
- if (numBitsToRead <= 0 || size_needed > this.size) {
111
- throw new Error("Invalid number of bits to read: " + size_needed + " of " + this.size);
93
+ * Move current read byte or bit position
94
+ *
95
+ * @param {number} offset - bytes to skip
96
+ * @param {number} bits - bits to skip
97
+ */
98
+ skip = this.fskip = function(bytes, bits){
99
+ this.#check_size(bytes || 0)
100
+ if((((bytes || 0) + this.offset) + Math.ceil((this.bitoffset + (bits||0)) /8) ) > this.size){
101
+ throw new Error("Seek outside of size of data: "+ this.size)
112
102
  }
103
+ this.bitoffset += (bits || 0) % 8
104
+ this.offset += (bytes || 0)
105
+ }
113
106
 
114
- let result = "0b";
115
- let startByteIndex = this.offset //cur byte
116
- let endByteIndex = this.offset + Math.floor(((numBitsToRead-1) + this.bitoffset) / 8) //end byte
117
- let bytesToRead = (endByteIndex - startByteIndex) + 1 //at least 1
118
- let startBitIndex = this.bitoffset
119
- let endBitIndex = ((numBitsToRead-1) + this.bitoffset)+1
120
- let bitArray = []
121
-
122
- let startByteIndexI = endByteIndex
123
-
124
- //big backwards read
125
- do {
126
- var element = this.data[startByteIndexI];
127
- element = element.toString(2).padStart(8, '0').split('')
128
- if(endian == "little"){
129
- element = element.reverse()
130
- }
131
- bitArray.push(element)
132
- startByteIndexI--
133
- bytesToRead--
134
- } while (bytesToRead != 0);
135
- if(endian == "big"){
136
- bitArray = bitArray.reverse()
107
+ /**
108
+ * Change current byte or bit read position
109
+ *
110
+ * @param {number} byte - byte to jump to
111
+ * @param {number} bit - bit to jump to (0-7)
112
+ */
113
+ goto = this.seek = this.fseek = this.jump = this.pointer = this.warp = this.fsetpos = function(byte, bit){
114
+ if((byte + Math.ceil((bit||0)/8) ) > this.size){
115
+ throw new Error("Goto outside of size of data: " + this.size)
137
116
  }
138
- bitArray = bitArray.flat()
139
- // console.log(bitArray)
140
- bitArray = bitArray.slice(startBitIndex,endBitIndex)
141
-
142
- this.offset = this.offset + Math.floor(((numBitsToRead) + this.bitoffset) / 8) //end byte
143
- this.bitoffset = ((numBitsToRead) + this.bitoffset) % 8
144
-
145
- result = result + bitArray.join("")
146
-
147
- return Number(result);
117
+ this.offset = byte
118
+ this.bitoffset = (bit || 0) % 8
148
119
  }
149
120
 
150
121
  /**
151
- *
152
- * bit field reader
153
- *
154
- * Note: When returning to a byte read, remaining bits are dropped
155
- *
156
- * @param {number} bits - bits to read
157
- * @returns number
158
- */
159
- bit = function(bits){
160
- return this.readBit(bits, this.endian)
122
+ * Set offset to start of file
123
+ */
124
+ rewind = this.gotostart = this.tostart = function(){
125
+ this.offset = 0
126
+ this.bitoffset = 0
161
127
  }
162
-
128
+
163
129
  /**
164
- *
165
- * bit field reader
166
- *
167
- * Note: When returning to a byte read, remaining bits are dropped
168
- *
169
- * @param {number} bits - bits to read
170
- * @returns number
171
- */
172
- readBitBE = function(bits){
173
- return this.readBit(bits, "big")
130
+ * Get the current byte position
131
+ *
132
+ * @return {number} current byte position
133
+ */
134
+ ftell = this.tell = this.fgetpos = function(){
135
+ return this.offset
174
136
  }
175
137
 
176
138
  /**
177
- *
178
- * bit field reader
179
- *
180
- * Note: When returning to a byte read, remaining bits are dropped
181
- *
182
- * @param {number} bits - bits to read
183
- * @returns number
184
- */
185
- bitbe = function(bits){
186
- return this.readBit(bits, "big")
139
+ * Truncates array from start to current position unless supplied
140
+ * Note: Does not affect supplied data
141
+ * @param {number} startOffset - Start location, default 0
142
+ * @param {number} endOffset - end location, default current write position
143
+ */
144
+ clip = this.crop = this.truncate = this.slice = function(startOffset, endOffset){
145
+ return this.data.slice(startOffset || 0, endOffset || this.offset)
187
146
  }
188
-
147
+
189
148
  /**
190
- *
191
- * bit field reader
192
- *
193
- * Note: When returning to a byte read, remaining bits are dropped
194
- *
195
- * @param {number} bits - bits to read
196
- * @returns number
197
- */
198
- bitle = function(bits){
199
- return this.readBit(bits, "little")
149
+ * Returns current data
150
+ */
151
+ get = this.return = function(){
152
+ return this.data
200
153
  }
201
-
154
+
202
155
  /**
203
- *
204
- * bit field reader
205
- *
206
- * Note: When returning to a byte read, remaining bits are dropped
207
- *
208
- * @param {number} bits - bits to read
209
- * @returns number
210
- */
211
- readBitLE = function(bits){
212
- return this.readBit(bits, "little")
156
+ * removes reading data
157
+ */
158
+ end = this.close = this.done = this.finished = function(){
159
+ return this.data
213
160
  }
214
161
 
215
- //byte read
162
+ //
163
+ //bit reader
164
+ //
216
165
 
217
166
  /**
167
+ * Bit field reader
168
+ *
169
+ * Note: When returning to a byte read, remaining bits are dropped
170
+ *
171
+ * @param {number} bits - bits to read
172
+ * @param {boolean} unsigned - if the value is unsigned
173
+ * @param {string} endian - ``big`` or ``little`
218
174
  * @returns number
219
175
  */
220
- readByte = function(signed){
221
- this.#check_size(1)
222
- const read = (this.data[this.offset])
223
- this.offset += 1
224
- if(signed){
225
- return read
226
- } else {
227
- return read & 0xFF
176
+ readBit = this.bit = function(bits, unsigned, endian){
177
+ if(bits == undefined || typeof bits != "number"){
178
+ throw new Error("Enter number of bits to read")
179
+ }
180
+ if (bits <= 0 || bits > 32) {
181
+ throw new Error('Bit length must be between 1 and 32.');
182
+ }
183
+ const size_needed = ((((bits-1) + this.bitoffset) / 8) + this.offset)
184
+ if (bits <= 0 || size_needed > this.size) {
185
+ throw new Error("Invalid number of bits to read: " + size_needed + " of " + this.size);
186
+ }
187
+
188
+ var off_in_bits = (this.offset * 8) + this.bitoffset
189
+
190
+ var value = 0;
191
+
192
+ for (var i = 0; i < bits;) {
193
+ var remaining = bits - i;
194
+ var bitOffset = off_in_bits & 7;
195
+ var currentByte = this.data[off_in_bits >> 3];
196
+
197
+ var read = Math.min(remaining, 8 - bitOffset);
198
+
199
+ var mask, readBits;
200
+ if ((endian != undefined ? endian : this.endian) == "big") {
201
+
202
+ mask = ~(0xFF << read);
203
+ readBits = (currentByte >> (8 - read - bitOffset)) & mask;
204
+ value <<= read;
205
+ value |= readBits;
206
+
207
+ } else {
208
+
209
+ mask = ~(0xFF << read);
210
+ readBits = (currentByte >> bitOffset) & mask;
211
+ value |= readBits << i;
212
+
213
+ }
214
+
215
+ off_in_bits += read;
216
+ i += read;
217
+ }
218
+
219
+ this.offset = this.offset + Math.floor(((bits) + this.bitoffset) / 8) //end byte
220
+ this.bitoffset = ((bits) + this.bitoffset) % 8
221
+
222
+ if (unsigned == true) {
223
+
224
+ return value >>> 0;
225
+
226
+ }
227
+
228
+ if (bits !== 32 && value & (1 << (bits - 1))) {
229
+ value |= -1 ^ ((1 << bits) - 1);
228
230
  }
231
+
232
+ return value;
233
+
229
234
  }
230
235
 
231
236
  /**
237
+ * Bit field reader
238
+ *
239
+ * Note: When returning to a byte read, remaining bits are dropped
240
+ *
241
+ * @param {boolean} unsigned - if the value is unsigned
232
242
  * @returns number
233
243
  */
234
- readUByte = function(){
235
- return this.readByte(true)
244
+ bit1 = function(unsigned){
245
+ return this.bit(1, unsigned)
236
246
  }
237
247
 
238
248
  /**
249
+ * Bit field reader
250
+ *
251
+ * Note: When returning to a byte read, remaining bits are dropped
252
+ *
253
+ * @param {boolean} unsigned - if the value is unsigned
239
254
  * @returns number
240
255
  */
241
- ubyte = function(){
242
- return this.readByte(true)
256
+ bit1le = function(unsigned){
257
+ return this.bit(1, unsigned, "little")
243
258
  }
259
+
244
260
  /**
261
+ * Bit field reader
262
+ *
263
+ * Note: When returning to a byte read, remaining bits are dropped
264
+ *
265
+ * @param {boolean} unsigned - if the value is unsigned
245
266
  * @returns number
246
267
  */
247
- byte = function(){
248
- return this.readByte(false)
268
+ bit1be = function(unsigned){
269
+ return this.bit(1, unsigned, "big")
249
270
  }
250
-
251
271
  /**
272
+ * Bit field reader
273
+ *
274
+ * Note: When returning to a byte read, remaining bits are dropped
275
+ *
252
276
  * @returns number
253
277
  */
254
- uint8 = function(){
255
- return this.readByte(true)
278
+ ubit1 = function(){
279
+ return this.bit(1, true)
256
280
  }
281
+
257
282
  /**
283
+ * Bit field reader
284
+ *
285
+ * Note: When returning to a byte read, remaining bits are dropped
286
+ *
258
287
  * @returns number
259
288
  */
260
- int8 = function(){
261
- return this.readByte(false)
289
+ ubit1le = function(){
290
+ return this.bit(1, true, "little")
262
291
  }
263
292
 
264
- //short16 read
265
-
266
293
  /**
294
+ * Bit field reader
295
+ *
296
+ * Note: When returning to a byte read, remaining bits are dropped
297
+ *
267
298
  * @returns number
268
299
  */
269
- readInt16LE = function(signed){
270
- this.#check_size(2)
271
- const read = (this.data[this.offset + 1] << 8) | this.data[this.offset];
272
- this.offset += 2
273
- if(signed){
274
- return read
275
- } else {
276
- return read & 0xFFFF
277
- }
300
+ ubit1be = function(){
301
+ return this.bit(1, true, "big")
278
302
  }
279
-
303
+
280
304
  /**
305
+ * Bit field reader
306
+ *
307
+ * Note: When returning to a byte read, remaining bits are dropped
308
+ *
309
+ * @param {boolean} unsigned - if the value is unsigned
281
310
  * @returns number
282
311
  */
283
- readInt16BE = function(signed){
284
- this.#check_size(2)
285
- const read = (this.data[this.offset] << 8) | this.data[this.offset + 1];
286
- this.offset += 2
287
- if(signed){
288
- return read
289
- } else {
290
- return read & 0xFFFF
291
- }
312
+ bit2 = function(unsigned){
313
+ return this.bit(2, unsigned)
292
314
  }
293
315
 
294
316
  /**
317
+ * Bit field reader
318
+ *
319
+ * Note: When returning to a byte read, remaining bits are dropped
320
+ *
321
+ * @param {boolean} unsigned - if the value is unsigned
295
322
  * @returns number
296
323
  */
297
- readUInt16 = function(){
298
- if(this.endian == "little"){
299
- return this.readInt16LE(true)
300
- } else {
301
- return this.readInt16BE(true)
302
- }
324
+ bit2le = function(unsigned){
325
+ return this.bit(2, unsigned, "little")
303
326
  }
304
327
 
305
328
  /**
329
+ * Bit field reader
330
+ *
331
+ * Note: When returning to a byte read, remaining bits are dropped
332
+ *
333
+ * @param {boolean} unsigned - if the value is unsigned
306
334
  * @returns number
307
335
  */
308
- readInt16 = function(){
309
- if(this.endian == "little"){
310
- return this.readInt16LE(false)
311
- } else {
312
- return this.readInt16BE(false)
313
- }
314
- }
315
-
336
+ bit2be = function(unsigned){
337
+ return this.bit(2, unsigned, "big")
338
+ }
316
339
  /**
340
+ * Bit field reader
341
+ *
342
+ * Note: When returning to a byte read, remaining bits are dropped
343
+ *
317
344
  * @returns number
318
345
  */
319
- readUShort = function(){
320
- return this.readUInt16()
346
+ ubit2 = function(){
347
+ return this.bit(2, true)
321
348
  }
322
349
 
323
350
  /**
351
+ * Bit field reader
352
+ *
353
+ * Note: When returning to a byte read, remaining bits are dropped
354
+ *
324
355
  * @returns number
325
356
  */
326
- readShort = function(){
327
- return this.readInt16()
357
+ ubit2le = function(){
358
+ return this.bit(2, true, "little")
328
359
  }
329
360
 
330
361
  /**
362
+ * Bit field reader
363
+ *
364
+ * Note: When returning to a byte read, remaining bits are dropped
365
+ *
331
366
  * @returns number
332
367
  */
333
- ushort = function(){
334
- return this.readUInt16()
368
+ ubit2be = function(){
369
+ return this.bit(2, true, "big")
335
370
  }
336
371
 
337
372
  /**
373
+ * Bit field reader
374
+ *
375
+ * Note: When returning to a byte read, remaining bits are dropped
376
+ *
377
+ * @param {boolean} unsigned - if the value is unsigned
338
378
  * @returns number
339
379
  */
340
- short = function (){
341
- return this.readInt16()
380
+ bit3 = function(unsigned){
381
+ return this.bit(3, unsigned)
342
382
  }
343
383
 
344
384
  /**
385
+ * Bit field reader
386
+ *
387
+ * Note: When returning to a byte read, remaining bits are dropped
388
+ *
389
+ * @param {boolean} unsigned - if the value is unsigned
345
390
  * @returns number
346
391
  */
347
- uint16 = function(){
348
- return this.readUInt16()
392
+ bit3le = function(unsigned){
393
+ return this.bit(3, unsigned, "little")
349
394
  }
350
395
 
351
396
  /**
397
+ * Bit field reader
398
+ *
399
+ * Note: When returning to a byte read, remaining bits are dropped
400
+ *
401
+ * @param {boolean} unsigned - if the value is unsigned
352
402
  * @returns number
353
403
  */
354
- int16 = function (){
355
- return this.readInt16()
404
+ bit3be = function(unsigned){
405
+ return this.bit(3, unsigned, "big")
356
406
  }
357
-
358
- //int read
359
-
360
407
  /**
408
+ * Bit field reader
409
+ *
410
+ * Note: When returning to a byte read, remaining bits are dropped
411
+ *
361
412
  * @returns number
362
413
  */
363
- readInt32LE = function(signed){
364
- this.#check_size(4)
365
- const read = ((this.data[this.offset + 3] << 24) | (this.data[this.offset + 2] << 16) | (this.data[this.offset + 1] << 8) | this.data[this.offset])
366
- this.offset += 4
367
- if(signed){
368
- return read
369
- } else {
370
- return read >>> 0
371
- }
414
+ ubit3 = function(){
415
+ return this.bit(3, true)
372
416
  }
373
417
 
374
418
  /**
419
+ * Bit field reader
420
+ *
421
+ * Note: When returning to a byte read, remaining bits are dropped
422
+ *
375
423
  * @returns number
376
424
  */
377
- readInt32BE = function(signed){
378
- this.#check_size(4)
379
- const read = (this.data[this.offset] << 24) | (this.data[this.offset + 1] << 16) | (this.data[this.offset + 2] << 8) | this.data[this.offset + 3]
380
- this.offset += 4
381
- if(signed){
382
- return read
383
- } else {
384
- return read >>> 0
385
- }
425
+ ubit3le = function(){
426
+ return this.bit(3, true, "little")
386
427
  }
387
428
 
388
429
  /**
430
+ * Bit field reader
431
+ *
432
+ * Note: When returning to a byte read, remaining bits are dropped
433
+ *
389
434
  * @returns number
390
435
  */
391
- readUInt32 = function(){
392
- if(this.endian == "little"){
393
- return this.readInt32LE(true)
394
- } else {
395
- return this.readInt32BE(true)
396
- }
436
+ ubit3be = function(){
437
+ return this.bit(3, true, "big")
397
438
  }
398
-
439
+
399
440
  /**
441
+ * Bit field reader
442
+ *
443
+ * Note: When returning to a byte read, remaining bits are dropped
444
+ *
445
+ * @param {boolean} unsigned - if the value is unsigned
400
446
  * @returns number
401
447
  */
402
- readInt32 = function(){
403
- if(this.endian == "little"){
404
- return this.readInt32LE(false)
405
- } else {
406
- return this.readInt32BE(false)
407
- }
448
+ bit4 = function(unsigned){
449
+ return this.bit(4, unsigned)
408
450
  }
409
451
 
410
452
  /**
453
+ * Bit field reader
454
+ *
455
+ * Note: When returning to a byte read, remaining bits are dropped
456
+ *
457
+ * @param {boolean} unsigned - if the value is unsigned
411
458
  * @returns number
412
459
  */
413
- readUInt = function(){
414
- return this.readUInt32()
460
+ bit4le = function(unsigned){
461
+ return this.bit(4, unsigned, "little")
415
462
  }
416
463
 
417
464
  /**
465
+ * Bit field reader
466
+ *
467
+ * Note: When returning to a byte read, remaining bits are dropped
468
+ *
469
+ * @param {boolean} unsigned - if the value is unsigned
418
470
  * @returns number
419
471
  */
420
- readInt = function(){
421
- return this.readInt32()
472
+ bit4be = function(unsigned){
473
+ return this.bit(4, unsigned, "big")
422
474
  }
423
-
424
475
  /**
476
+ * Bit field reader
477
+ *
478
+ * Note: When returning to a byte read, remaining bits are dropped
479
+ *
425
480
  * @returns number
426
481
  */
427
- int = function(){
428
- return this.readInt32()
482
+ ubit4 = function(){
483
+ return this.bit(4, true)
429
484
  }
430
485
 
431
486
  /**
487
+ * Bit field reader
488
+ *
489
+ * Note: When returning to a byte read, remaining bits are dropped
490
+ *
432
491
  * @returns number
433
492
  */
434
- uint = function(){
435
- return this.readUInt32()
493
+ ubit4le = function(){
494
+ return this.bit(4, true, "little")
436
495
  }
437
496
 
438
- //string reader
439
-
440
497
  /**
441
- * inculde length or reads until 0 byte
442
- * can include terminate character (as number), defaults to 0
443
- * @param {number} length - number
444
- * @param {any} terminateValue - number
445
- * @returns string
498
+ * Bit field reader
499
+ *
500
+ * Note: When returning to a byte read, remaining bits are dropped
501
+ *
502
+ * @returns number
446
503
  */
447
- string = function(length,terminateValue){
448
- var terminate = 0
449
- if(length != undefined){
450
- this.#check_size(length)
451
- }
452
- if(typeof terminateValue == "number"){
453
- terminate = terminateValue & 0xFF
454
- }
455
- if (length === undefined) {
456
- let currentString = '';
457
-
458
- for (let i = this.offset; i < this.size; i++) {
459
- const byte = this.readUByte();
460
- if (byte != terminate) {
461
- currentString += String.fromCharCode(byte);
462
- } else {
463
- break;
464
- }
465
- }
466
- return currentString;
467
- } else {
468
- // If a length is specified, read that many bytes
469
- const string = String.fromCharCode.apply(null, this.data.slice(this.offset, this.offset+length))
470
- this.offset += length
471
- return string;
472
- }
504
+ ubit4be = function(){
505
+ return this.bit(4, true, "big")
473
506
  }
474
507
 
475
508
  /**
476
- * inculde length or reads until 0 byte
477
- * can include terminate character (as number), defaults to 0
478
- * @param {number} length - number
479
- * @param {any} terminateValue - number
480
- * @returns string
509
+ * Bit field reader
510
+ *
511
+ * Note: When returning to a byte read, remaining bits are dropped
512
+ *
513
+ * @param {boolean} unsigned - if the value is unsigned
514
+ * @returns number
481
515
  */
482
- readString = function(length,terminateValue){
483
- return this.string(length,terminateValue)
516
+ bit5 = function(unsigned){
517
+ return this.bit(5, unsigned)
484
518
  }
485
519
 
486
520
  /**
487
- * can switch byte order on demand, default to set endianness
488
- * inculde length in bytes or reads until 0 short
489
- * can include terminate character (as number), defaults to 0
490
- * @param {number} byteorder - number
491
- * @param {number} length - number
492
- * @param {any} terminateValue - number
493
- * @returns string
521
+ * Bit field reader
522
+ *
523
+ * Note: When returning to a byte read, remaining bits are dropped
524
+ *
525
+ * @param {boolean} unsigned - if the value is unsigned
526
+ * @returns number
494
527
  */
495
- string16 = function(byteorder,length,terminateValue){
496
- var terminate = 0x0000
497
- if(length != undefined){
498
- this.#check_size(length)
499
- }
500
- if(typeof terminateValue == "number"){
501
- terminate = terminateValue & 0xFFFF
502
- }
503
- if(byteorder != undefined && !(byteorder == "big" || byteorder == "little")){
504
- throw Error("byteorder must be big or little")
505
- }
506
- if (length == undefined) {
507
- let currentString = '';
508
-
509
- for (let i = this.offset; i < this.size; i += 2) {
510
- var short = terminateValue;
511
- var endian = byteorder || this.endian
512
- if(endian == "big"){
513
- short = this.readInt16BE(true)
514
- }
515
- if(endian == "little"){
516
- short = this.readInt16LE(true)
517
- }
518
-
519
- if (short != terminate) {
520
- currentString += String.fromCharCode(short);
521
- } else {
522
- break;
523
- }
524
- }
525
- return currentString;
526
- } else {
527
- let currentString = '';
528
-
529
- for (let i = 0; i < (length/2); i++) {
530
- var short = terminateValue;
531
- var endian = byteorder || this.endian
532
- if(endian == "big"){
533
- short = this.readInt16BE(true)
534
- }
535
- if(endian == "little"){
536
- short = this.readInt16LE(true)
537
- }
538
- currentString += String.fromCharCode(short);
539
- }
540
- return currentString;
541
- }
528
+ bit5le = function(unsigned){
529
+ return this.bit(5, unsigned, "little")
542
530
  }
543
531
 
544
532
  /**
545
- * can switch byte order on demand, default to set endianness
546
- * inculde length in bytes or reads until 0 short
547
- * can include terminate character (as number), defaults to 0
548
- * @param {string} byteorder - ```big``` or ```little```
549
- * @param {number} length - number
550
- * @param {any} terminateValue - number
551
- * @returns string
533
+ * Bit field reader
534
+ *
535
+ * Note: When returning to a byte read, remaining bits are dropped
536
+ *
537
+ * @param {boolean} unsigned - if the value is unsigned
538
+ * @returns number
552
539
  */
553
- read16String = function(byteorder,length,terminateValue){
554
- return this.string16(byteorder,length,terminateValue)
540
+ bit5be = function(unsigned){
541
+ return this.bit(5, unsigned, "big")
555
542
  }
556
-
557
543
  /**
558
- * can switch byte order on demand, default to set endianness
559
- * inculde length in bytes or reads until 0 short
560
- * can include terminate character (as number), defaults to 0
561
- * @param {string} byteorder - ```big``` or ```little```
562
- * @param {number} length - number
563
- * @param {any} terminateValue - number
564
- * @returns string
544
+ * Bit field reader
545
+ *
546
+ * Note: When returning to a byte read, remaining bits are dropped
547
+ *
548
+ * @returns number
565
549
  */
566
- readCString = function(byteorder,length,terminateValue){
567
- return this.string16(byteorder,length,terminateValue)
550
+ ubit5 = function(){
551
+ return this.bit(5, true)
568
552
  }
569
553
 
570
554
  /**
571
- * can switch byte order on demand, default to set endianness
572
- * inculde length in bytes or reads until 0 short
573
- * can include terminate character (as number), defaults to 0
574
- * @param {string} byteorder - ```big``` or ```little```
575
- * @param {number} length - number
576
- * @param {any} terminateValue - number
577
- * @returns string
555
+ * Bit field reader
556
+ *
557
+ * Note: When returning to a byte read, remaining bits are dropped
558
+ *
559
+ * @returns number
578
560
  */
579
- cstring = function(byteorder,length,terminateValue){
580
- return this.string16(byteorder,length,terminateValue)
561
+ ubit5le = function(){
562
+ return this.bit(5, true, "little")
581
563
  }
582
564
 
583
- //int64 reader
584
-
585
565
  /**
566
+ * Bit field reader
567
+ *
568
+ * Note: When returning to a byte read, remaining bits are dropped
569
+ *
586
570
  * @returns number
587
571
  */
588
- readInt64LE = function(signed) {
589
- this.#check_size(8)
590
-
591
- // Convert the byte array to a BigInt
592
- let value = BigInt(0);
593
- for (let i = 0; i < 8; i++) {
594
- value |= BigInt(this.data[this.offset]) << BigInt(8 * i);
595
- this.offset += 1
596
- }
597
- if(signed){
598
- if (value & (BigInt(1) << BigInt(63))) {
599
- value -= BigInt(1) << BigInt(64);
600
- }
601
- return value;
602
- } else {
603
- return value;
604
- }
572
+ ubit5be = function(){
573
+ return this.bit(5, true, "big")
605
574
  }
606
575
 
607
576
  /**
577
+ * Bit field reader
578
+ *
579
+ * Note: When returning to a byte read, remaining bits are dropped
580
+ *
581
+ * @param {boolean} unsigned - if the value is unsigned
608
582
  * @returns number
609
583
  */
610
- readInt64BE = function(signed) {
611
- this.#check_size(8)
612
-
613
- // Convert the byte array to a BigInt
614
- let value = BigInt(0);
615
- for (let i = 0; i < 8; i++) {
616
- value = (value << BigInt(8)) | BigInt(this.data[this.offset]);
617
- this.offset += 1
618
- }
619
- if(signed){
620
- if (value & (BigInt(1) << BigInt(63))) {
621
- value -= BigInt(1) << BigInt(64);
622
- }
623
- return value;
624
- } else {
625
- return value;
626
- }
584
+ bit6 = function(unsigned){
585
+ return this.bit(6, unsigned)
627
586
  }
628
587
 
629
588
  /**
589
+ * Bit field reader
590
+ *
591
+ * Note: When returning to a byte read, remaining bits are dropped
592
+ *
593
+ * @param {boolean} unsigned - if the value is unsigned
630
594
  * @returns number
631
595
  */
632
- readUInt64 = function(){
633
- if(this.endian == "little"){
634
- return this.readInt64LE(true)
635
- } else {
636
- return this.readInt64BE(true)
637
- }
596
+ bit6le = function(unsigned){
597
+ return this.bit(6, unsigned, "little")
638
598
  }
639
599
 
640
600
  /**
601
+ * Bit field reader
602
+ *
603
+ * Note: When returning to a byte read, remaining bits are dropped
604
+ *
605
+ * @param {boolean} unsigned - if the value is unsigned
641
606
  * @returns number
642
607
  */
643
- readInt64 = function(){
644
- if(this.endian == "little"){
645
- return this.readInt32LE(false)
646
- } else {
647
- return this.readInt32BE(false)
648
- }
608
+ bit6be = function(unsigned){
609
+ return this.bit(6, unsigned, "big")
649
610
  }
650
-
651
611
  /**
612
+ * Bit field reader
613
+ *
614
+ * Note: When returning to a byte read, remaining bits are dropped
615
+ *
652
616
  * @returns number
653
617
  */
654
- uint64 = function(){
655
- if(this.endian == "little"){
656
- return this.readInt64LE(true)
657
- } else {
658
- return this.readInt64BE(true)
659
- }
618
+ ubit6 = function(){
619
+ return this.bit(6, true)
660
620
  }
661
621
 
662
622
  /**
623
+ * Bit field reader
624
+ *
625
+ * Note: When returning to a byte read, remaining bits are dropped
626
+ *
663
627
  * @returns number
664
628
  */
665
- int64 = function(){
666
- if(this.endian == "little"){
667
- return this.readInt32LE(false)
668
- } else {
669
- return this.readInt32BE(false)
670
- }
629
+ ubit6le = function(){
630
+ return this.bit(6, true, "little")
671
631
  }
672
632
 
673
- //float read
674
-
675
633
  /**
634
+ * Bit field reader
635
+ *
636
+ * Note: When returning to a byte read, remaining bits are dropped
637
+ *
676
638
  * @returns number
677
639
  */
678
- readFloat = function(order){
679
- this.#check_size(4)
680
- var uint32Value;
681
- var endian = order == undefined ? this.endian : order
682
- if(endian == "little"){
683
- uint32Value = this.readInt32LE(true)
684
- } else {
685
- uint32Value = this.readInt32BE(true)
686
- }
687
- // Check if the value is negative (i.e., the most significant bit is set)
688
- const isNegative = (uint32Value & 0x80000000) !== 0;
689
-
690
- // Extract the exponent and fraction parts
691
- const exponent = (uint32Value >> 23) & 0xFF;
692
- const fraction = uint32Value & 0x7FFFFF;
693
-
694
- // Calculate the float value
695
- let floatValue;
696
-
697
- if (exponent === 0) {
698
- // Denormalized number (exponent is 0)
699
- floatValue = Math.pow(-1, isNegative) * Math.pow(2, -126) * (fraction / Math.pow(2, 23));
700
- } else if (exponent === 0xFF) {
701
- // Infinity or NaN (exponent is 255)
702
- floatValue = fraction === 0 ? (isNegative ? Number.NEGATIVE_INFINITY : Number.POSITIVE_INFINITY) : Number.NaN;
703
- } else {
704
- // Normalized number
705
- floatValue = Math.pow(-1, isNegative) * Math.pow(2, exponent - 127) * (1 + fraction / Math.pow(2, 23));
706
- }
707
-
708
- return floatValue;
640
+ ubit6be = function(){
641
+ return this.bit(6, true, "big")
709
642
  }
710
643
 
711
644
  /**
645
+ * Bit field reader
646
+ *
647
+ * Note: When returning to a byte read, remaining bits are dropped
648
+ *
649
+ * @param {boolean} unsigned - if the value is unsigned
712
650
  * @returns number
713
651
  */
714
- float = function(){
715
- return this.readFloat()
652
+ bit7 = function(unsigned){
653
+ return this.bit(7, unsigned)
716
654
  }
717
655
 
718
656
  /**
657
+ * Bit field reader
658
+ *
659
+ * Note: When returning to a byte read, remaining bits are dropped
660
+ *
661
+ * @param {boolean} unsigned - if the value is unsigned
719
662
  * @returns number
720
663
  */
721
- floatbe = function(){
722
- return this.readFloat(true)
664
+ bit7le = function(unsigned){
665
+ return this.bit(7, unsigned, "little")
723
666
  }
724
667
 
725
- /**
668
+ /**
669
+ * Bit field reader
670
+ *
671
+ * Note: When returning to a byte read, remaining bits are dropped
672
+ *
673
+ * @param {boolean} unsigned - if the value is unsigned
726
674
  * @returns number
727
675
  */
728
- floatle = function(){
729
- return this.readFloat(false)
676
+ bit7be = function(unsigned){
677
+ return this.bit(7, unsigned, "big")
730
678
  }
731
-
732
679
  /**
680
+ * Bit field reader
681
+ *
682
+ * Note: When returning to a byte read, remaining bits are dropped
683
+ *
733
684
  * @returns number
734
685
  */
735
- readFloatBE = function(){
736
- return this.readFloat(true)
686
+ ubit7 = function(){
687
+ return this.bit(7, true)
737
688
  }
738
689
 
739
690
  /**
691
+ * Bit field reader
692
+ *
693
+ * Note: When returning to a byte read, remaining bits are dropped
694
+ *
740
695
  * @returns number
741
696
  */
742
- readFloatLE = function(){
743
- return this.readFloat(false)
697
+ ubit7le = function(){
698
+ return this.bit(7, true, "little")
744
699
  }
745
700
 
746
- //half float read
747
-
748
701
  /**
702
+ * Bit field reader
703
+ *
704
+ * Note: When returning to a byte read, remaining bits are dropped
705
+ *
749
706
  * @returns number
750
707
  */
751
- readHalfFloat = function(order){
752
- this.#check_size(2)
753
- var uint16Value;
754
- var endian = order == undefined ? this.endian : order
755
- if(endian == "little"){
756
- uint16Value = this.readInt16LE(true)
757
- } else {
758
- uint16Value = this.readInt16BE(true)
759
- }
760
- const sign = (uint16Value & 0x8000) >> 15;
761
- const exponent = (uint16Value & 0x7C00) >> 10;
762
- const fraction = uint16Value & 0x03FF;
763
-
764
- let floatValue;
765
-
766
- if (exponent === 0) {
767
- if (fraction === 0) {
768
- floatValue = (sign === 0) ? 0 : -0; // +/-0
769
- } else {
770
- // Denormalized number
771
- floatValue = (sign === 0 ? 1 : -1) * Math.pow(2, -14) * (fraction / 0x0400);
772
- }
773
- } else if (exponent === 0x1F) {
774
- if (fraction === 0) {
775
- floatValue = (sign === 0) ? Number.POSITIVE_INFINITY : Number.NEGATIVE_INFINITY;
776
- } else {
777
- floatValue = Number.NaN;
778
- }
779
- } else {
780
- // Normalized number
781
- floatValue = (sign === 0 ? 1 : -1) * Math.pow(2, exponent - 15) * (1 + fraction / 0x0400);
782
- }
783
-
784
- return floatValue;
708
+ ubit7be = function(){
709
+ return this.bit(7, true, "big")
785
710
  }
786
-
711
+
787
712
  /**
713
+ * Bit field reader
714
+ *
715
+ * Note: When returning to a byte read, remaining bits are dropped
716
+ *
717
+ * @param {boolean} unsigned - if the value is unsigned
788
718
  * @returns number
789
719
  */
790
- halffloat = function(){
791
- return this.readHalfFloat()
720
+ bit8 = function(unsigned){
721
+ return this.bit(8, unsigned)
792
722
  }
793
723
 
794
724
  /**
725
+ * Bit field reader
726
+ *
727
+ * Note: When returning to a byte read, remaining bits are dropped
728
+ *
729
+ * @param {boolean} unsigned - if the value is unsigned
795
730
  * @returns number
796
731
  */
797
- halffloatbe = function(){
798
- return this.readHalfFloat(true)
732
+ bit8le = function(unsigned){
733
+ return this.bit(8, unsigned, "little")
799
734
  }
800
735
 
801
- /**
736
+ /**
737
+ * Bit field reader
738
+ *
739
+ * Note: When returning to a byte read, remaining bits are dropped
740
+ *
741
+ * @param {boolean} unsigned - if the value is unsigned
742
+ * @returns number
743
+ */
744
+ bit8be = function(unsigned){
745
+ return this.bit(8, unsigned, "big")
746
+ }
747
+ /**
748
+ * Bit field reader
749
+ *
750
+ * Note: When returning to a byte read, remaining bits are dropped
751
+ *
802
752
  * @returns number
803
753
  */
804
- halffloatle = function(){
805
- return this.readHalfFloat(false)
754
+ ubit8 = function(){
755
+ return this.bit(8, true)
806
756
  }
807
757
 
808
758
  /**
759
+ * Bit field reader
760
+ *
761
+ * Note: When returning to a byte read, remaining bits are dropped
762
+ *
809
763
  * @returns number
810
764
  */
811
- readHalfFloatBE = function(){
812
- return this.readHalfFloat(true)
765
+ ubit8le = function(){
766
+ return this.bit(8, true, "little")
813
767
  }
814
768
 
815
769
  /**
770
+ * Bit field reader
771
+ *
772
+ * Note: When returning to a byte read, remaining bits are dropped
773
+ *
774
+ * @returns number
775
+ */
776
+ ubit8be = function(){
777
+ return this.bit(8, true, "big")
778
+ }
779
+
780
+ /**
781
+ * Bit field reader
782
+ *
783
+ * Note: When returning to a byte read, remaining bits are dropped
784
+ *
785
+ * @param {boolean} unsigned - if the value is unsigned
816
786
  * @returns number
817
787
  */
818
- readHalfFloatLE = function(){
819
- return this.readHalfFloat(false)
788
+ bit9 = function(unsigned){
789
+ return this.bit(9, unsigned)
820
790
  }
821
791
 
822
- //doublefloat reader
792
+ /**
793
+ * Bit field reader
794
+ *
795
+ * Note: When returning to a byte read, remaining bits are dropped
796
+ *
797
+ * @param {boolean} unsigned - if the value is unsigned
798
+ * @returns number
799
+ */
800
+ bit9le = function(unsigned){
801
+ return this.bit(9, unsigned, "little")
802
+ }
823
803
 
824
804
  /**
805
+ * Bit field reader
806
+ *
807
+ * Note: When returning to a byte read, remaining bits are dropped
808
+ *
809
+ * @param {boolean} unsigned - if the value is unsigned
825
810
  * @returns number
826
811
  */
827
- readDoubleFloat = function(order){
812
+ bit9be = function(unsigned){
813
+ return this.bit(9, unsigned, "big")
814
+ }
815
+ /**
816
+ * Bit field reader
817
+ *
818
+ * Note: When returning to a byte read, remaining bits are dropped
819
+ *
820
+ * @returns number
821
+ */
822
+ ubit9 = function(){
823
+ return this.bit(9, true)
824
+ }
825
+
826
+ /**
827
+ * Bit field reader
828
+ *
829
+ * Note: When returning to a byte read, remaining bits are dropped
830
+ *
831
+ * @returns number
832
+ */
833
+ ubit9le = function(){
834
+ return this.bit(9, true, "little")
835
+ }
836
+
837
+ /**
838
+ * Bit field reader
839
+ *
840
+ * Note: When returning to a byte read, remaining bits are dropped
841
+ *
842
+ * @returns number
843
+ */
844
+ ubit9be = function(){
845
+ return this.bit(9, true, "big")
846
+ }
847
+
848
+ /**
849
+ * Bit field reader
850
+ *
851
+ * Note: When returning to a byte read, remaining bits are dropped
852
+ *
853
+ * @param {boolean} unsigned - if the value is unsigned
854
+ * @returns number
855
+ */
856
+ bit10 = function(unsigned){
857
+ return this.bit(10, unsigned)
858
+ }
859
+
860
+ /**
861
+ * Bit field reader
862
+ *
863
+ * Note: When returning to a byte read, remaining bits are dropped
864
+ *
865
+ * @param {boolean} unsigned - if the value is unsigned
866
+ * @returns number
867
+ */
868
+ bit10le = function(unsigned){
869
+ return this.bit(10, unsigned, "little")
870
+ }
871
+
872
+ /**
873
+ * Bit field reader
874
+ *
875
+ * Note: When returning to a byte read, remaining bits are dropped
876
+ *
877
+ * @param {boolean} unsigned - if the value is unsigned
878
+ * @returns number
879
+ */
880
+ bit10be = function(unsigned){
881
+ return this.bit(10, unsigned, "big")
882
+ }
883
+ /**
884
+ * Bit field reader
885
+ *
886
+ * Note: When returning to a byte read, remaining bits are dropped
887
+ *
888
+ * @returns number
889
+ */
890
+ ubit10 = function(){
891
+ return this.bit(10, true)
892
+ }
893
+
894
+ /**
895
+ * Bit field reader
896
+ *
897
+ * Note: When returning to a byte read, remaining bits are dropped
898
+ *
899
+ * @returns number
900
+ */
901
+ ubit10le = function(){
902
+ return this.bit(10, true, "little")
903
+ }
904
+
905
+ /**
906
+ * Bit field reader
907
+ *
908
+ * Note: When returning to a byte read, remaining bits are dropped
909
+ *
910
+ * @returns number
911
+ */
912
+ ubit10be = function(){
913
+ return this.bit(10, true, "big")
914
+ }
915
+
916
+ /**
917
+ * Bit field reader
918
+ *
919
+ * Note: When returning to a byte read, remaining bits are dropped
920
+ *
921
+ * @param {boolean} unsigned - if the value is unsigned
922
+ * @returns number
923
+ */
924
+ bit11 = function(unsigned){
925
+ return this.bit(11, unsigned)
926
+ }
927
+
928
+ /**
929
+ * Bit field reader
930
+ *
931
+ * Note: When returning to a byte read, remaining bits are dropped
932
+ *
933
+ * @param {boolean} unsigned - if the value is unsigned
934
+ * @returns number
935
+ */
936
+ bit11le = function(unsigned){
937
+ return this.bit(11, unsigned, "little")
938
+ }
939
+
940
+ /**
941
+ * Bit field reader
942
+ *
943
+ * Note: When returning to a byte read, remaining bits are dropped
944
+ *
945
+ * @param {boolean} unsigned - if the value is unsigned
946
+ * @returns number
947
+ */
948
+ bit11be = function(unsigned){
949
+ return this.bit(11, unsigned, "big")
950
+ }
951
+ /**
952
+ * Bit field reader
953
+ *
954
+ * Note: When returning to a byte read, remaining bits are dropped
955
+ *
956
+ * @returns number
957
+ */
958
+ ubit11 = function(){
959
+ return this.bit(11, true)
960
+ }
961
+
962
+ /**
963
+ * Bit field reader
964
+ *
965
+ * Note: When returning to a byte read, remaining bits are dropped
966
+ *
967
+ * @returns number
968
+ */
969
+ ubit11le = function(){
970
+ return this.bit(11, true, "little")
971
+ }
972
+
973
+ /**
974
+ * Bit field reader
975
+ *
976
+ * Note: When returning to a byte read, remaining bits are dropped
977
+ *
978
+ * @returns number
979
+ */
980
+ ubit11be = function(){
981
+ return this.bit(11, true, "big")
982
+ }
983
+
984
+ /**
985
+ * Bit field reader
986
+ *
987
+ * Note: When returning to a byte read, remaining bits are dropped
988
+ *
989
+ * @param {boolean} unsigned - if the value is unsigned
990
+ * @returns number
991
+ */
992
+ bit12 = function(unsigned){
993
+ return this.bit(12, unsigned)
994
+ }
995
+
996
+ /**
997
+ * Bit field reader
998
+ *
999
+ * Note: When returning to a byte read, remaining bits are dropped
1000
+ *
1001
+ * @param {boolean} unsigned - if the value is unsigned
1002
+ * @returns number
1003
+ */
1004
+ bit12le = function(unsigned){
1005
+ return this.bit(12, unsigned, "little")
1006
+ }
1007
+
1008
+ /**
1009
+ * Bit field reader
1010
+ *
1011
+ * Note: When returning to a byte read, remaining bits are dropped
1012
+ *
1013
+ * @param {boolean} unsigned - if the value is unsigned
1014
+ * @returns number
1015
+ */
1016
+ bit12be = function(unsigned){
1017
+ return this.bit(12, unsigned, "big")
1018
+ }
1019
+ /**
1020
+ * Bit field reader
1021
+ *
1022
+ * Note: When returning to a byte read, remaining bits are dropped
1023
+ *
1024
+ * @returns number
1025
+ */
1026
+ ubit12 = function(){
1027
+ return this.bit(12, true)
1028
+ }
1029
+
1030
+ /**
1031
+ * Bit field reader
1032
+ *
1033
+ * Note: When returning to a byte read, remaining bits are dropped
1034
+ *
1035
+ * @returns number
1036
+ */
1037
+ ubit12le = function(){
1038
+ return this.bit(12, true, "little")
1039
+ }
1040
+
1041
+ /**
1042
+ * Bit field reader
1043
+ *
1044
+ * Note: When returning to a byte read, remaining bits are dropped
1045
+ *
1046
+ * @returns number
1047
+ */
1048
+ ubit12be = function(){
1049
+ return this.bit(12, true, "big")
1050
+ }
1051
+
1052
+ /**
1053
+ * Bit field reader
1054
+ *
1055
+ * Note: When returning to a byte read, remaining bits are dropped
1056
+ *
1057
+ * @param {boolean} unsigned - if the value is unsigned
1058
+ * @returns number
1059
+ */
1060
+ bit13 = function(unsigned){
1061
+ return this.bit(13, unsigned)
1062
+ }
1063
+
1064
+ /**
1065
+ * Bit field reader
1066
+ *
1067
+ * Note: When returning to a byte read, remaining bits are dropped
1068
+ *
1069
+ * @param {boolean} unsigned - if the value is unsigned
1070
+ * @returns number
1071
+ */
1072
+ bit13le = function(unsigned){
1073
+ return this.bit(13, unsigned, "little")
1074
+ }
1075
+
1076
+ /**
1077
+ * Bit field reader
1078
+ *
1079
+ * Note: When returning to a byte read, remaining bits are dropped
1080
+ *
1081
+ * @param {boolean} unsigned - if the value is unsigned
1082
+ * @returns number
1083
+ */
1084
+ bit13be = function(unsigned){
1085
+ return this.bit(13, unsigned, "big")
1086
+ }
1087
+ /**
1088
+ * Bit field reader
1089
+ *
1090
+ * Note: When returning to a byte read, remaining bits are dropped
1091
+ *
1092
+ * @returns number
1093
+ */
1094
+ ubit13 = function(){
1095
+ return this.bit(13, true)
1096
+ }
1097
+
1098
+ /**
1099
+ * Bit field reader
1100
+ *
1101
+ * Note: When returning to a byte read, remaining bits are dropped
1102
+ *
1103
+ * @returns number
1104
+ */
1105
+ ubit13le = function(){
1106
+ return this.bit(13, true, "little")
1107
+ }
1108
+
1109
+ /**
1110
+ * Bit field reader
1111
+ *
1112
+ * Note: When returning to a byte read, remaining bits are dropped
1113
+ *
1114
+ * @returns number
1115
+ */
1116
+ ubit13be = function(){
1117
+ return this.bit(13, true, "big")
1118
+ }
1119
+
1120
+ /**
1121
+ * Bit field reader
1122
+ *
1123
+ * Note: When returning to a byte read, remaining bits are dropped
1124
+ *
1125
+ * @param {boolean} unsigned - if the value is unsigned
1126
+ * @returns number
1127
+ */
1128
+ bit14 = function(unsigned){
1129
+ return this.bit(14, unsigned)
1130
+ }
1131
+
1132
+ /**
1133
+ * Bit field reader
1134
+ *
1135
+ * Note: When returning to a byte read, remaining bits are dropped
1136
+ *
1137
+ * @param {boolean} unsigned - if the value is unsigned
1138
+ * @returns number
1139
+ */
1140
+ bit14le = function(unsigned){
1141
+ return this.bit(14, unsigned, "little")
1142
+ }
1143
+
1144
+ /**
1145
+ * Bit field reader
1146
+ *
1147
+ * Note: When returning to a byte read, remaining bits are dropped
1148
+ *
1149
+ * @param {boolean} unsigned - if the value is unsigned
1150
+ * @returns number
1151
+ */
1152
+ bit14be = function(unsigned){
1153
+ return this.bit(14, unsigned, "big")
1154
+ }
1155
+ /**
1156
+ * Bit field reader
1157
+ *
1158
+ * Note: When returning to a byte read, remaining bits are dropped
1159
+ *
1160
+ * @returns number
1161
+ */
1162
+ ubit14 = function(){
1163
+ return this.bit(14, true)
1164
+ }
1165
+
1166
+ /**
1167
+ * Bit field reader
1168
+ *
1169
+ * Note: When returning to a byte read, remaining bits are dropped
1170
+ *
1171
+ * @returns number
1172
+ */
1173
+ ubit14le = function(){
1174
+ return this.bit(14, true, "little")
1175
+ }
1176
+
1177
+ /**
1178
+ * Bit field reader
1179
+ *
1180
+ * Note: When returning to a byte read, remaining bits are dropped
1181
+ *
1182
+ * @returns number
1183
+ */
1184
+ ubit14be = function(){
1185
+ return this.bit(14, true, "big")
1186
+ }
1187
+
1188
+ /**
1189
+ * Bit field reader
1190
+ *
1191
+ * Note: When returning to a byte read, remaining bits are dropped
1192
+ *
1193
+ * @param {boolean} unsigned - if the value is unsigned
1194
+ * @returns number
1195
+ */
1196
+ bit15 = function(unsigned){
1197
+ return this.bit(15, unsigned)
1198
+ }
1199
+
1200
+ /**
1201
+ * Bit field reader
1202
+ *
1203
+ * Note: When returning to a byte read, remaining bits are dropped
1204
+ *
1205
+ * @param {boolean} unsigned - if the value is unsigned
1206
+ * @returns number
1207
+ */
1208
+ bit15le = function(unsigned){
1209
+ return this.bit(15, unsigned, "little")
1210
+ }
1211
+
1212
+ /**
1213
+ * Bit field reader
1214
+ *
1215
+ * Note: When returning to a byte read, remaining bits are dropped
1216
+ *
1217
+ * @param {boolean} unsigned - if the value is unsigned
1218
+ * @returns number
1219
+ */
1220
+ bit15be = function(unsigned){
1221
+ return this.bit(15, unsigned, "big")
1222
+ }
1223
+ /**
1224
+ * Bit field reader
1225
+ *
1226
+ * Note: When returning to a byte read, remaining bits are dropped
1227
+ *
1228
+ * @returns number
1229
+ */
1230
+ ubit15 = function(){
1231
+ return this.bit(15, true)
1232
+ }
1233
+
1234
+ /**
1235
+ * Bit field reader
1236
+ *
1237
+ * Note: When returning to a byte read, remaining bits are dropped
1238
+ *
1239
+ * @returns number
1240
+ */
1241
+ ubit15le = function(){
1242
+ return this.bit(15, true, "little")
1243
+ }
1244
+
1245
+ /**
1246
+ * Bit field reader
1247
+ *
1248
+ * Note: When returning to a byte read, remaining bits are dropped
1249
+ *
1250
+ * @returns number
1251
+ */
1252
+ ubit15be = function(){
1253
+ return this.bit(15, true, "big")
1254
+ }
1255
+
1256
+ /**
1257
+ * Bit field reader
1258
+ *
1259
+ * Note: When returning to a byte read, remaining bits are dropped
1260
+ *
1261
+ * @param {boolean} unsigned - if the value is unsigned
1262
+ * @returns number
1263
+ */
1264
+ bit16 = function(unsigned){
1265
+ return this.bit(16, unsigned)
1266
+ }
1267
+
1268
+ /**
1269
+ * Bit field reader
1270
+ *
1271
+ * Note: When returning to a byte read, remaining bits are dropped
1272
+ *
1273
+ * @param {boolean} unsigned - if the value is unsigned
1274
+ * @returns number
1275
+ */
1276
+ bit16le = function(unsigned){
1277
+ return this.bit(16, unsigned, "little")
1278
+ }
1279
+
1280
+ /**
1281
+ * Bit field reader
1282
+ *
1283
+ * Note: When returning to a byte read, remaining bits are dropped
1284
+ *
1285
+ * @param {boolean} unsigned - if the value is unsigned
1286
+ * @returns number
1287
+ */
1288
+ bit16be = function(unsigned){
1289
+ return this.bit(16, unsigned, "big")
1290
+ }
1291
+ /**
1292
+ * Bit field reader
1293
+ *
1294
+ * Note: When returning to a byte read, remaining bits are dropped
1295
+ *
1296
+ * @returns number
1297
+ */
1298
+ ubit16 = function(){
1299
+ return this.bit(16, true)
1300
+ }
1301
+
1302
+ /**
1303
+ * Bit field reader
1304
+ *
1305
+ * Note: When returning to a byte read, remaining bits are dropped
1306
+ *
1307
+ * @returns number
1308
+ */
1309
+ ubit16le = function(){
1310
+ return this.bit(16, true, "little")
1311
+ }
1312
+
1313
+ /**
1314
+ * Bit field reader
1315
+ *
1316
+ * Note: When returning to a byte read, remaining bits are dropped
1317
+ *
1318
+ * @returns number
1319
+ */
1320
+ ubit16be = function(){
1321
+ return this.bit(16, true, "big")
1322
+ }
1323
+
1324
+ /**
1325
+ * Bit field reader
1326
+ *
1327
+ * Note: When returning to a byte read, remaining bits are dropped
1328
+ *
1329
+ * @param {boolean} unsigned - if the value is unsigned
1330
+ * @returns number
1331
+ */
1332
+ bit17 = function(unsigned){
1333
+ return this.bit(17, unsigned)
1334
+ }
1335
+
1336
+ /**
1337
+ * Bit field reader
1338
+ *
1339
+ * Note: When returning to a byte read, remaining bits are dropped
1340
+ *
1341
+ * @param {boolean} unsigned - if the value is unsigned
1342
+ * @returns number
1343
+ */
1344
+ bit17le = function(unsigned){
1345
+ return this.bit(17, unsigned, "little")
1346
+ }
1347
+
1348
+ /**
1349
+ * Bit field reader
1350
+ *
1351
+ * Note: When returning to a byte read, remaining bits are dropped
1352
+ *
1353
+ * @param {boolean} unsigned - if the value is unsigned
1354
+ * @returns number
1355
+ */
1356
+ bit17be = function(unsigned){
1357
+ return this.bit(17, unsigned, "big")
1358
+ }
1359
+ /**
1360
+ * Bit field reader
1361
+ *
1362
+ * Note: When returning to a byte read, remaining bits are dropped
1363
+ *
1364
+ * @returns number
1365
+ */
1366
+ ubit17 = function(){
1367
+ return this.bit(17, true)
1368
+ }
1369
+
1370
+ /**
1371
+ * Bit field reader
1372
+ *
1373
+ * Note: When returning to a byte read, remaining bits are dropped
1374
+ *
1375
+ * @returns number
1376
+ */
1377
+ ubit17le = function(){
1378
+ return this.bit(17, true, "little")
1379
+ }
1380
+
1381
+ /**
1382
+ * Bit field reader
1383
+ *
1384
+ * Note: When returning to a byte read, remaining bits are dropped
1385
+ *
1386
+ * @returns number
1387
+ */
1388
+ ubit17be = function(){
1389
+ return this.bit(17, true, "big")
1390
+ }
1391
+
1392
+ /**
1393
+ * Bit field reader
1394
+ *
1395
+ * Note: When returning to a byte read, remaining bits are dropped
1396
+ *
1397
+ * @param {boolean} unsigned - if the value is unsigned
1398
+ * @returns number
1399
+ */
1400
+ bit18 = function(unsigned){
1401
+ return this.bit(18, unsigned)
1402
+ }
1403
+
1404
+ /**
1405
+ * Bit field reader
1406
+ *
1407
+ * Note: When returning to a byte read, remaining bits are dropped
1408
+ *
1409
+ * @param {boolean} unsigned - if the value is unsigned
1410
+ * @returns number
1411
+ */
1412
+ bit18le = function(unsigned){
1413
+ return this.bit(18, unsigned, "little")
1414
+ }
1415
+
1416
+ /**
1417
+ * Bit field reader
1418
+ *
1419
+ * Note: When returning to a byte read, remaining bits are dropped
1420
+ *
1421
+ * @param {boolean} unsigned - if the value is unsigned
1422
+ * @returns number
1423
+ */
1424
+ bit18be = function(unsigned){
1425
+ return this.bit(18, unsigned, "big")
1426
+ }
1427
+ /**
1428
+ * Bit field reader
1429
+ *
1430
+ * Note: When returning to a byte read, remaining bits are dropped
1431
+ *
1432
+ * @returns number
1433
+ */
1434
+ ubit18 = function(){
1435
+ return this.bit(18, true)
1436
+ }
1437
+
1438
+ /**
1439
+ * Bit field reader
1440
+ *
1441
+ * Note: When returning to a byte read, remaining bits are dropped
1442
+ *
1443
+ * @returns number
1444
+ */
1445
+ ubit18le = function(){
1446
+ return this.bit(18, true, "little")
1447
+ }
1448
+
1449
+ /**
1450
+ * Bit field reader
1451
+ *
1452
+ * Note: When returning to a byte read, remaining bits are dropped
1453
+ *
1454
+ * @returns number
1455
+ */
1456
+ ubit18be = function(){
1457
+ return this.bit(18, true, "big")
1458
+ }
1459
+
1460
+ /**
1461
+ * Bit field reader
1462
+ *
1463
+ * Note: When returning to a byte read, remaining bits are dropped
1464
+ *
1465
+ * @param {boolean} unsigned - if the value is unsigned
1466
+ * @returns number
1467
+ */
1468
+ bit19 = function(unsigned){
1469
+ return this.bit(19, unsigned)
1470
+ }
1471
+
1472
+ /**
1473
+ * Bit field reader
1474
+ *
1475
+ * Note: When returning to a byte read, remaining bits are dropped
1476
+ *
1477
+ * @param {boolean} unsigned - if the value is unsigned
1478
+ * @returns number
1479
+ */
1480
+ bit19le = function(unsigned){
1481
+ return this.bit(19, unsigned, "little")
1482
+ }
1483
+
1484
+ /**
1485
+ * Bit field reader
1486
+ *
1487
+ * Note: When returning to a byte read, remaining bits are dropped
1488
+ *
1489
+ * @param {boolean} unsigned - if the value is unsigned
1490
+ * @returns number
1491
+ */
1492
+ bit19be = function(unsigned){
1493
+ return this.bit(19, unsigned, "big")
1494
+ }
1495
+ /**
1496
+ * Bit field reader
1497
+ *
1498
+ * Note: When returning to a byte read, remaining bits are dropped
1499
+ *
1500
+ * @returns number
1501
+ */
1502
+ ubit19 = function(){
1503
+ return this.bit(19, true)
1504
+ }
1505
+
1506
+ /**
1507
+ * Bit field reader
1508
+ *
1509
+ * Note: When returning to a byte read, remaining bits are dropped
1510
+ *
1511
+ * @returns number
1512
+ */
1513
+ ubit19le = function(){
1514
+ return this.bit(19, true, "little")
1515
+ }
1516
+
1517
+ /**
1518
+ * Bit field reader
1519
+ *
1520
+ * Note: When returning to a byte read, remaining bits are dropped
1521
+ *
1522
+ * @returns number
1523
+ */
1524
+ ubit19be = function(){
1525
+ return this.bit(19, true, "big")
1526
+ }
1527
+
1528
+ /**
1529
+ * Bit field reader
1530
+ *
1531
+ * Note: When returning to a byte read, remaining bits are dropped
1532
+ *
1533
+ * @param {boolean} unsigned - if the value is unsigned
1534
+ * @returns number
1535
+ */
1536
+ bit20 = function(unsigned){
1537
+ return this.bit(20, unsigned)
1538
+ }
1539
+
1540
+ /**
1541
+ * Bit field reader
1542
+ *
1543
+ * Note: When returning to a byte read, remaining bits are dropped
1544
+ *
1545
+ * @param {boolean} unsigned - if the value is unsigned
1546
+ * @returns number
1547
+ */
1548
+ bit20le = function(unsigned){
1549
+ return this.bit(20, unsigned, "little")
1550
+ }
1551
+
1552
+ /**
1553
+ * Bit field reader
1554
+ *
1555
+ * Note: When returning to a byte read, remaining bits are dropped
1556
+ *
1557
+ * @param {boolean} unsigned - if the value is unsigned
1558
+ * @returns number
1559
+ */
1560
+ bit20be = function(unsigned){
1561
+ return this.bit(20, unsigned, "big")
1562
+ }
1563
+ /**
1564
+ * Bit field reader
1565
+ *
1566
+ * Note: When returning to a byte read, remaining bits are dropped
1567
+ *
1568
+ * @returns number
1569
+ */
1570
+ ubit20 = function(){
1571
+ return this.bit(20, true)
1572
+ }
1573
+
1574
+ /**
1575
+ * Bit field reader
1576
+ *
1577
+ * Note: When returning to a byte read, remaining bits are dropped
1578
+ *
1579
+ * @returns number
1580
+ */
1581
+ ubit20le = function(){
1582
+ return this.bit(20, true, "little")
1583
+ }
1584
+
1585
+ /**
1586
+ * Bit field reader
1587
+ *
1588
+ * Note: When returning to a byte read, remaining bits are dropped
1589
+ *
1590
+ * @returns number
1591
+ */
1592
+ ubit20be = function(){
1593
+ return this.bit(20, true, "big")
1594
+ }
1595
+
1596
+ /**
1597
+ * Bit field reader
1598
+ *
1599
+ * Note: When returning to a byte read, remaining bits are dropped
1600
+ *
1601
+ * @param {boolean} unsigned - if the value is unsigned
1602
+ * @returns number
1603
+ */
1604
+ bit21 = function(unsigned){
1605
+ return this.bit(21, unsigned)
1606
+ }
1607
+
1608
+ /**
1609
+ * Bit field reader
1610
+ *
1611
+ * Note: When returning to a byte read, remaining bits are dropped
1612
+ *
1613
+ * @param {boolean} unsigned - if the value is unsigned
1614
+ * @returns number
1615
+ */
1616
+ bit21le = function(unsigned){
1617
+ return this.bit(21, unsigned, "little")
1618
+ }
1619
+
1620
+ /**
1621
+ * Bit field reader
1622
+ *
1623
+ * Note: When returning to a byte read, remaining bits are dropped
1624
+ *
1625
+ * @param {boolean} unsigned - if the value is unsigned
1626
+ * @returns number
1627
+ */
1628
+ bit21be = function(unsigned){
1629
+ return this.bit(21, unsigned, "big")
1630
+ }
1631
+ /**
1632
+ * Bit field reader
1633
+ *
1634
+ * Note: When returning to a byte read, remaining bits are dropped
1635
+ *
1636
+ * @returns number
1637
+ */
1638
+ ubit21 = function(){
1639
+ return this.bit(21, true)
1640
+ }
1641
+
1642
+ /**
1643
+ * Bit field reader
1644
+ *
1645
+ * Note: When returning to a byte read, remaining bits are dropped
1646
+ *
1647
+ * @returns number
1648
+ */
1649
+ ubit21le = function(){
1650
+ return this.bit(21, true, "little")
1651
+ }
1652
+
1653
+ /**
1654
+ * Bit field reader
1655
+ *
1656
+ * Note: When returning to a byte read, remaining bits are dropped
1657
+ *
1658
+ * @returns number
1659
+ */
1660
+ ubit21be = function(){
1661
+ return this.bit(21, true, "big")
1662
+ }
1663
+
1664
+ /**
1665
+ * Bit field reader
1666
+ *
1667
+ * Note: When returning to a byte read, remaining bits are dropped
1668
+ *
1669
+ * @param {boolean} unsigned - if the value is unsigned
1670
+ * @returns number
1671
+ */
1672
+ bit22 = function(unsigned){
1673
+ return this.bit(22, unsigned)
1674
+ }
1675
+
1676
+ /**
1677
+ * Bit field reader
1678
+ *
1679
+ * Note: When returning to a byte read, remaining bits are dropped
1680
+ *
1681
+ * @param {boolean} unsigned - if the value is unsigned
1682
+ * @returns number
1683
+ */
1684
+ bit22le = function(unsigned){
1685
+ return this.bit(22, unsigned, "little")
1686
+ }
1687
+
1688
+ /**
1689
+ * Bit field reader
1690
+ *
1691
+ * Note: When returning to a byte read, remaining bits are dropped
1692
+ *
1693
+ * @param {boolean} unsigned - if the value is unsigned
1694
+ * @returns number
1695
+ */
1696
+ bit22be = function(unsigned){
1697
+ return this.bit(22, unsigned, "big")
1698
+ }
1699
+ /**
1700
+ * Bit field reader
1701
+ *
1702
+ * Note: When returning to a byte read, remaining bits are dropped
1703
+ *
1704
+ * @returns number
1705
+ */
1706
+ ubit22 = function(){
1707
+ return this.bit(22, true)
1708
+ }
1709
+
1710
+ /**
1711
+ * Bit field reader
1712
+ *
1713
+ * Note: When returning to a byte read, remaining bits are dropped
1714
+ *
1715
+ * @returns number
1716
+ */
1717
+ ubit22le = function(){
1718
+ return this.bit(22, true, "little")
1719
+ }
1720
+
1721
+ /**
1722
+ * Bit field reader
1723
+ *
1724
+ * Note: When returning to a byte read, remaining bits are dropped
1725
+ *
1726
+ * @returns number
1727
+ */
1728
+ ubit22be = function(){
1729
+ return this.bit(22, true, "big")
1730
+ }
1731
+
1732
+ /**
1733
+ * Bit field reader
1734
+ *
1735
+ * Note: When returning to a byte read, remaining bits are dropped
1736
+ *
1737
+ * @param {boolean} unsigned - if the value is unsigned
1738
+ * @returns number
1739
+ */
1740
+ bit23 = function(unsigned){
1741
+ return this.bit(23, unsigned)
1742
+ }
1743
+
1744
+ /**
1745
+ * Bit field reader
1746
+ *
1747
+ * Note: When returning to a byte read, remaining bits are dropped
1748
+ *
1749
+ * @param {boolean} unsigned - if the value is unsigned
1750
+ * @returns number
1751
+ */
1752
+ bit23le = function(unsigned){
1753
+ return this.bit(23, unsigned, "little")
1754
+ }
1755
+
1756
+ /**
1757
+ * Bit field reader
1758
+ *
1759
+ * Note: When returning to a byte read, remaining bits are dropped
1760
+ *
1761
+ * @param {boolean} unsigned - if the value is unsigned
1762
+ * @returns number
1763
+ */
1764
+ bit23be = function(unsigned){
1765
+ return this.bit(23, unsigned, "big")
1766
+ }
1767
+ /**
1768
+ * Bit field reader
1769
+ *
1770
+ * Note: When returning to a byte read, remaining bits are dropped
1771
+ *
1772
+ * @returns number
1773
+ */
1774
+ ubit23 = function(){
1775
+ return this.bit(23, true)
1776
+ }
1777
+
1778
+ /**
1779
+ * Bit field reader
1780
+ *
1781
+ * Note: When returning to a byte read, remaining bits are dropped
1782
+ *
1783
+ * @returns number
1784
+ */
1785
+ ubit23le = function(){
1786
+ return this.bit(23, true, "little")
1787
+ }
1788
+
1789
+ /**
1790
+ * Bit field reader
1791
+ *
1792
+ * Note: When returning to a byte read, remaining bits are dropped
1793
+ *
1794
+ * @returns number
1795
+ */
1796
+ ubit23be = function(){
1797
+ return this.bit(23, true, "big")
1798
+ }
1799
+
1800
+ /**
1801
+ * Bit field reader
1802
+ *
1803
+ * Note: When returning to a byte read, remaining bits are dropped
1804
+ *
1805
+ * @param {boolean} unsigned - if the value is unsigned
1806
+ * @returns number
1807
+ */
1808
+ bit24 = function(unsigned){
1809
+ return this.bit(24, unsigned)
1810
+ }
1811
+
1812
+ /**
1813
+ * Bit field reader
1814
+ *
1815
+ * Note: When returning to a byte read, remaining bits are dropped
1816
+ *
1817
+ * @param {boolean} unsigned - if the value is unsigned
1818
+ * @returns number
1819
+ */
1820
+ bit24le = function(unsigned){
1821
+ return this.bit(24, unsigned, "little")
1822
+ }
1823
+
1824
+ /**
1825
+ * Bit field reader
1826
+ *
1827
+ * Note: When returning to a byte read, remaining bits are dropped
1828
+ *
1829
+ * @param {boolean} unsigned - if the value is unsigned
1830
+ * @returns number
1831
+ */
1832
+ bit24be = function(unsigned){
1833
+ return this.bit(24, unsigned, "big")
1834
+ }
1835
+ /**
1836
+ * Bit field reader
1837
+ *
1838
+ * Note: When returning to a byte read, remaining bits are dropped
1839
+ *
1840
+ * @returns number
1841
+ */
1842
+ ubit24 = function(){
1843
+ return this.bit(24, true)
1844
+ }
1845
+
1846
+ /**
1847
+ * Bit field reader
1848
+ *
1849
+ * Note: When returning to a byte read, remaining bits are dropped
1850
+ *
1851
+ * @returns number
1852
+ */
1853
+ ubit24le = function(){
1854
+ return this.bit(24, true, "little")
1855
+ }
1856
+
1857
+ /**
1858
+ * Bit field reader
1859
+ *
1860
+ * Note: When returning to a byte read, remaining bits are dropped
1861
+ *
1862
+ * @returns number
1863
+ */
1864
+ ubit24be = function(){
1865
+ return this.bit(24, true, "big")
1866
+ }
1867
+
1868
+ /**
1869
+ * Bit field reader
1870
+ *
1871
+ * Note: When returning to a byte read, remaining bits are dropped
1872
+ *
1873
+ * @param {boolean} unsigned - if the value is unsigned
1874
+ * @returns number
1875
+ */
1876
+ bit25 = function(unsigned){
1877
+ return this.bit(25, unsigned)
1878
+ }
1879
+
1880
+ /**
1881
+ * Bit field reader
1882
+ *
1883
+ * Note: When returning to a byte read, remaining bits are dropped
1884
+ *
1885
+ * @param {boolean} unsigned - if the value is unsigned
1886
+ * @returns number
1887
+ */
1888
+ bit25le = function(unsigned){
1889
+ return this.bit(25, unsigned, "little")
1890
+ }
1891
+
1892
+ /**
1893
+ * Bit field reader
1894
+ *
1895
+ * Note: When returning to a byte read, remaining bits are dropped
1896
+ *
1897
+ * @param {boolean} unsigned - if the value is unsigned
1898
+ * @returns number
1899
+ */
1900
+ bit25be = function(unsigned){
1901
+ return this.bit(25, unsigned, "big")
1902
+ }
1903
+ /**
1904
+ * Bit field reader
1905
+ *
1906
+ * Note: When returning to a byte read, remaining bits are dropped
1907
+ *
1908
+ * @returns number
1909
+ */
1910
+ ubit25 = function(){
1911
+ return this.bit(25, true)
1912
+ }
1913
+
1914
+ /**
1915
+ * Bit field reader
1916
+ *
1917
+ * Note: When returning to a byte read, remaining bits are dropped
1918
+ *
1919
+ * @returns number
1920
+ */
1921
+ ubit25le = function(){
1922
+ return this.bit(25, true, "little")
1923
+ }
1924
+
1925
+ /**
1926
+ * Bit field reader
1927
+ *
1928
+ * Note: When returning to a byte read, remaining bits are dropped
1929
+ *
1930
+ * @returns number
1931
+ */
1932
+ ubit25be = function(){
1933
+ return this.bit(25, true, "big")
1934
+ }
1935
+
1936
+ /**
1937
+ * Bit field reader
1938
+ *
1939
+ * Note: When returning to a byte read, remaining bits are dropped
1940
+ *
1941
+ * @param {boolean} unsigned - if the value is unsigned
1942
+ * @returns number
1943
+ */
1944
+ bit26 = function(unsigned){
1945
+ return this.bit(26, unsigned)
1946
+ }
1947
+
1948
+ /**
1949
+ * Bit field reader
1950
+ *
1951
+ * Note: When returning to a byte read, remaining bits are dropped
1952
+ *
1953
+ * @param {boolean} unsigned - if the value is unsigned
1954
+ * @returns number
1955
+ */
1956
+ bit26le = function(unsigned){
1957
+ return this.bit(26, unsigned, "little")
1958
+ }
1959
+
1960
+ /**
1961
+ * Bit field reader
1962
+ *
1963
+ * Note: When returning to a byte read, remaining bits are dropped
1964
+ *
1965
+ * @param {boolean} unsigned - if the value is unsigned
1966
+ * @returns number
1967
+ */
1968
+ bit26be = function(unsigned){
1969
+ return this.bit(26, unsigned, "big")
1970
+ }
1971
+ /**
1972
+ * Bit field reader
1973
+ *
1974
+ * Note: When returning to a byte read, remaining bits are dropped
1975
+ *
1976
+ * @returns number
1977
+ */
1978
+ ubit26 = function(){
1979
+ return this.bit(26, true)
1980
+ }
1981
+
1982
+ /**
1983
+ * Bit field reader
1984
+ *
1985
+ * Note: When returning to a byte read, remaining bits are dropped
1986
+ *
1987
+ * @returns number
1988
+ */
1989
+ ubit26le = function(){
1990
+ return this.bit(26, true, "little")
1991
+ }
1992
+
1993
+ /**
1994
+ * Bit field reader
1995
+ *
1996
+ * Note: When returning to a byte read, remaining bits are dropped
1997
+ *
1998
+ * @returns number
1999
+ */
2000
+ ubit26be = function(){
2001
+ return this.bit(26, true, "big")
2002
+ }
2003
+
2004
+ /**
2005
+ * Bit field reader
2006
+ *
2007
+ * Note: When returning to a byte read, remaining bits are dropped
2008
+ *
2009
+ * @param {boolean} unsigned - if the value is unsigned
2010
+ * @returns number
2011
+ */
2012
+ bit27 = function(unsigned){
2013
+ return this.bit(27, unsigned)
2014
+ }
2015
+
2016
+ /**
2017
+ * Bit field reader
2018
+ *
2019
+ * Note: When returning to a byte read, remaining bits are dropped
2020
+ *
2021
+ * @param {boolean} unsigned - if the value is unsigned
2022
+ * @returns number
2023
+ */
2024
+ bit27le = function(unsigned){
2025
+ return this.bit(27, unsigned, "little")
2026
+ }
2027
+
2028
+ /**
2029
+ * Bit field reader
2030
+ *
2031
+ * Note: When returning to a byte read, remaining bits are dropped
2032
+ *
2033
+ * @param {boolean} unsigned - if the value is unsigned
2034
+ * @returns number
2035
+ */
2036
+ bit27be = function(unsigned){
2037
+ return this.bit(27, unsigned, "big")
2038
+ }
2039
+ /**
2040
+ * Bit field reader
2041
+ *
2042
+ * Note: When returning to a byte read, remaining bits are dropped
2043
+ *
2044
+ * @returns number
2045
+ */
2046
+ ubit27 = function(){
2047
+ return this.bit(27, true)
2048
+ }
2049
+
2050
+ /**
2051
+ * Bit field reader
2052
+ *
2053
+ * Note: When returning to a byte read, remaining bits are dropped
2054
+ *
2055
+ * @returns number
2056
+ */
2057
+ ubit27le = function(){
2058
+ return this.bit(27, true, "little")
2059
+ }
2060
+
2061
+ /**
2062
+ * Bit field reader
2063
+ *
2064
+ * Note: When returning to a byte read, remaining bits are dropped
2065
+ *
2066
+ * @returns number
2067
+ */
2068
+ ubit27be = function(){
2069
+ return this.bit(27, true, "big")
2070
+ }
2071
+
2072
+ /**
2073
+ * Bit field reader
2074
+ *
2075
+ * Note: When returning to a byte read, remaining bits are dropped
2076
+ *
2077
+ * @param {boolean} unsigned - if the value is unsigned
2078
+ * @returns number
2079
+ */
2080
+ bit28 = function(unsigned){
2081
+ return this.bit(28, unsigned)
2082
+ }
2083
+
2084
+ /**
2085
+ * Bit field reader
2086
+ *
2087
+ * Note: When returning to a byte read, remaining bits are dropped
2088
+ *
2089
+ * @param {boolean} unsigned - if the value is unsigned
2090
+ * @returns number
2091
+ */
2092
+ bit28le = function(unsigned){
2093
+ return this.bit(28, unsigned, "little")
2094
+ }
2095
+
2096
+ /**
2097
+ * Bit field reader
2098
+ *
2099
+ * Note: When returning to a byte read, remaining bits are dropped
2100
+ *
2101
+ * @param {boolean} unsigned - if the value is unsigned
2102
+ * @returns number
2103
+ */
2104
+ bit28be = function(unsigned){
2105
+ return this.bit(28, unsigned, "big")
2106
+ }
2107
+ /**
2108
+ * Bit field reader
2109
+ *
2110
+ * Note: When returning to a byte read, remaining bits are dropped
2111
+ *
2112
+ * @returns number
2113
+ */
2114
+ ubit28 = function(){
2115
+ return this.bit(28, true)
2116
+ }
2117
+
2118
+ /**
2119
+ * Bit field reader
2120
+ *
2121
+ * Note: When returning to a byte read, remaining bits are dropped
2122
+ *
2123
+ * @returns number
2124
+ */
2125
+ ubit28le = function(){
2126
+ return this.bit(28, true, "little")
2127
+ }
2128
+
2129
+ /**
2130
+ * Bit field reader
2131
+ *
2132
+ * Note: When returning to a byte read, remaining bits are dropped
2133
+ *
2134
+ * @returns number
2135
+ */
2136
+ ubit28be = function(){
2137
+ return this.bit(28, true, "big")
2138
+ }
2139
+
2140
+ /**
2141
+ * Bit field reader
2142
+ *
2143
+ * Note: When returning to a byte read, remaining bits are dropped
2144
+ *
2145
+ * @param {boolean} unsigned - if the value is unsigned
2146
+ * @returns number
2147
+ */
2148
+ bit29 = function(unsigned){
2149
+ return this.bit(29, unsigned)
2150
+ }
2151
+
2152
+ /**
2153
+ * Bit field reader
2154
+ *
2155
+ * Note: When returning to a byte read, remaining bits are dropped
2156
+ *
2157
+ * @param {boolean} unsigned - if the value is unsigned
2158
+ * @returns number
2159
+ */
2160
+ bit29le = function(unsigned){
2161
+ return this.bit(29, unsigned, "little")
2162
+ }
2163
+
2164
+ /**
2165
+ * Bit field reader
2166
+ *
2167
+ * Note: When returning to a byte read, remaining bits are dropped
2168
+ *
2169
+ * @param {boolean} unsigned - if the value is unsigned
2170
+ * @returns number
2171
+ */
2172
+ bit29be = function(unsigned){
2173
+ return this.bit(29, unsigned, "big")
2174
+ }
2175
+ /**
2176
+ * Bit field reader
2177
+ *
2178
+ * Note: When returning to a byte read, remaining bits are dropped
2179
+ *
2180
+ * @returns number
2181
+ */
2182
+ ubit29 = function(){
2183
+ return this.bit(29, true)
2184
+ }
2185
+
2186
+ /**
2187
+ * Bit field reader
2188
+ *
2189
+ * Note: When returning to a byte read, remaining bits are dropped
2190
+ *
2191
+ * @returns number
2192
+ */
2193
+ ubit29le = function(){
2194
+ return this.bit(29, true, "little")
2195
+ }
2196
+
2197
+ /**
2198
+ * Bit field reader
2199
+ *
2200
+ * Note: When returning to a byte read, remaining bits are dropped
2201
+ *
2202
+ * @returns number
2203
+ */
2204
+ ubit29be = function(){
2205
+ return this.bit(29, true, "big")
2206
+ }
2207
+
2208
+ /**
2209
+ * Bit field reader
2210
+ *
2211
+ * Note: When returning to a byte read, remaining bits are dropped
2212
+ *
2213
+ * @param {boolean} unsigned - if the value is unsigned
2214
+ * @returns number
2215
+ */
2216
+ bit30 = function(unsigned){
2217
+ return this.bit(30, unsigned)
2218
+ }
2219
+
2220
+ /**
2221
+ * Bit field reader
2222
+ *
2223
+ * Note: When returning to a byte read, remaining bits are dropped
2224
+ *
2225
+ * @param {boolean} unsigned - if the value is unsigned
2226
+ * @returns number
2227
+ */
2228
+ bit30le = function(unsigned){
2229
+ return this.bit(30, unsigned, "little")
2230
+ }
2231
+
2232
+ /**
2233
+ * Bit field reader
2234
+ *
2235
+ * Note: When returning to a byte read, remaining bits are dropped
2236
+ *
2237
+ * @param {boolean} unsigned - if the value is unsigned
2238
+ * @returns number
2239
+ */
2240
+ bit30be = function(unsigned){
2241
+ return this.bit(30, unsigned, "big")
2242
+ }
2243
+ /**
2244
+ * Bit field reader
2245
+ *
2246
+ * Note: When returning to a byte read, remaining bits are dropped
2247
+ *
2248
+ * @returns number
2249
+ */
2250
+ ubit30 = function(){
2251
+ return this.bit(30, true)
2252
+ }
2253
+
2254
+ /**
2255
+ * Bit field reader
2256
+ *
2257
+ * Note: When returning to a byte read, remaining bits are dropped
2258
+ *
2259
+ * @returns number
2260
+ */
2261
+ ubit30le = function(){
2262
+ return this.bit(30, true, "little")
2263
+ }
2264
+
2265
+ /**
2266
+ * Bit field reader
2267
+ *
2268
+ * Note: When returning to a byte read, remaining bits are dropped
2269
+ *
2270
+ * @returns number
2271
+ */
2272
+ ubit30be = function(){
2273
+ return this.bit(30, true, "big")
2274
+ }
2275
+
2276
+ /**
2277
+ * Bit field reader
2278
+ *
2279
+ * Note: When returning to a byte read, remaining bits are dropped
2280
+ *
2281
+ * @param {boolean} unsigned - if the value is unsigned
2282
+ * @returns number
2283
+ */
2284
+ bit31 = function(unsigned){
2285
+ return this.bit(31, unsigned)
2286
+ }
2287
+
2288
+ /**
2289
+ * Bit field reader
2290
+ *
2291
+ * Note: When returning to a byte read, remaining bits are dropped
2292
+ *
2293
+ * @param {boolean} unsigned - if the value is unsigned
2294
+ * @returns number
2295
+ */
2296
+ bit31le = function(unsigned){
2297
+ return this.bit(31, unsigned, "little")
2298
+ }
2299
+
2300
+ /**
2301
+ * Bit field reader
2302
+ *
2303
+ * Note: When returning to a byte read, remaining bits are dropped
2304
+ *
2305
+ * @param {boolean} unsigned - if the value is unsigned
2306
+ * @returns number
2307
+ */
2308
+ bit31be = function(unsigned){
2309
+ return this.bit(31, unsigned, "big")
2310
+ }
2311
+ /**
2312
+ * Bit field reader
2313
+ *
2314
+ * Note: When returning to a byte read, remaining bits are dropped
2315
+ *
2316
+ * @returns number
2317
+ */
2318
+ ubit31 = function(){
2319
+ return this.bit(31, true)
2320
+ }
2321
+
2322
+ /**
2323
+ * Bit field reader
2324
+ *
2325
+ * Note: When returning to a byte read, remaining bits are dropped
2326
+ *
2327
+ * @returns number
2328
+ */
2329
+ ubit31le = function(){
2330
+ return this.bit(31, true, "little")
2331
+ }
2332
+
2333
+ /**
2334
+ * Bit field reader
2335
+ *
2336
+ * Note: When returning to a byte read, remaining bits are dropped
2337
+ *
2338
+ * @returns number
2339
+ */
2340
+ ubit31be = function(){
2341
+ return this.bit(31, true, "big")
2342
+ }
2343
+
2344
+ /**
2345
+ * Bit field reader
2346
+ *
2347
+ * Note: When returning to a byte read, remaining bits are dropped
2348
+ *
2349
+ * @param {boolean} unsigned - if the value is unsigned
2350
+ * @returns number
2351
+ */
2352
+ bit32 = function(unsigned){
2353
+ return this.bit(32, unsigned)
2354
+ }
2355
+
2356
+ /**
2357
+ * Bit field reader
2358
+ *
2359
+ * Note: When returning to a byte read, remaining bits are dropped
2360
+ *
2361
+ * @param {boolean} unsigned - if the value is unsigned
2362
+ * @returns number
2363
+ */
2364
+ bit32le = function(unsigned){
2365
+ return this.bit(32, unsigned, "little")
2366
+ }
2367
+
2368
+ /**
2369
+ * Bit field reader
2370
+ *
2371
+ * Note: When returning to a byte read, remaining bits are dropped
2372
+ *
2373
+ * @param {boolean} unsigned - if the value is unsigned
2374
+ * @returns number
2375
+ */
2376
+ bit32be = function(unsigned){
2377
+ return this.bit(32, unsigned, "big")
2378
+ }
2379
+ /**
2380
+ * Bit field reader
2381
+ *
2382
+ * Note: When returning to a byte read, remaining bits are dropped
2383
+ *
2384
+ * @returns number
2385
+ */
2386
+ ubit32 = function(){
2387
+ return this.bit(32, true)
2388
+ }
2389
+
2390
+ /**
2391
+ * Bit field reader
2392
+ *
2393
+ * Note: When returning to a byte read, remaining bits are dropped
2394
+ *
2395
+ * @returns number
2396
+ */
2397
+ ubit32le = function(){
2398
+ return this.bit(32, true, "little")
2399
+ }
2400
+
2401
+ /**
2402
+ * Bit field reader
2403
+ *
2404
+ * Note: When returning to a byte read, remaining bits are dropped
2405
+ *
2406
+ * @returns number
2407
+ */
2408
+ ubit32be = function(){
2409
+ return this.bit(32, true, "big")
2410
+ }
2411
+
2412
+ /**
2413
+ * Bit field reader
2414
+ *
2415
+ * Note: When returning to a byte read, remaining bits are dropped
2416
+ *
2417
+ * @param {number} bits - bits to read
2418
+ * @param {boolean} unsigned - if the value is unsigned
2419
+ * @returns number
2420
+ */
2421
+ readUBitBE = this.ubitbe = function(bits){
2422
+ return this.readBit(bits, true, "big")
2423
+ }
2424
+
2425
+ /**
2426
+ * Bit field reader
2427
+ *
2428
+ * Note: When returning to a byte read, remaining bits are dropped
2429
+ *
2430
+ * @param {number} bits - bits to read
2431
+ * @param {boolean} unsigned - if the value is unsigned
2432
+ * @returns number
2433
+ */
2434
+ readBitBE = this.bitbe = function(bits, unsigned){
2435
+ return this.readBit(bits, unsigned, "big")
2436
+ }
2437
+
2438
+ /**
2439
+ * Bit field reader
2440
+ *
2441
+ * Note: When returning to a byte read, remaining bits are dropped
2442
+ *
2443
+ * @param {number} bits - bits to read
2444
+ * @param {boolean} signed - if the value is unsigned
2445
+ * @returns number
2446
+ */
2447
+ readUBitLE = this.ubitle = function(bits){
2448
+ return this.readBit(bits, true, "little")
2449
+ }
2450
+
2451
+ /**
2452
+ * Bit field reader
2453
+ *
2454
+ * Note: When returning to a byte read, remaining bits are dropped
2455
+ *
2456
+ * @param {number} bits - bits to read
2457
+ * @param {boolean} unsigned - if the value is unsigned
2458
+ * @returns number
2459
+ */
2460
+ readBitLE = this.bitle = function(bits, signed){
2461
+ return this.readBit(bits, signed, "little")
2462
+ }
2463
+
2464
+ //
2465
+ //byte read
2466
+ //
2467
+
2468
+ /**
2469
+ * Read byte
2470
+ *
2471
+ * @param {boolean} unsigned - if value is unsigned or not
2472
+ * @returns number
2473
+ */
2474
+ readByte = this.byte = this.int8 = function(unsigned){
2475
+ this.#check_size(1)
2476
+ const read = (this.data[this.offset])
2477
+ this.offset += 1
2478
+ if(unsigned == true){
2479
+ return read & 0xFF
2480
+ } else {
2481
+ return read
2482
+ }
2483
+ }
2484
+
2485
+ /**
2486
+ * Read unsigned byte
2487
+ *
2488
+ * @returns number
2489
+ */
2490
+ readUByte = this.uint8 = this.ubyte = function(){
2491
+ return this.readByte(true)
2492
+ }
2493
+
2494
+ //
2495
+ //short16 read
2496
+ //
2497
+
2498
+ /**
2499
+ * Read short
2500
+ *
2501
+ * @param {boolean} unsigned - if value is unsigned or not
2502
+ * @param {string} endian - ```big``` or ```little```
2503
+ * @returns number
2504
+ */
2505
+ readInt16 = this.short = this.int16 = this.word = function(unsigned, endian){
2506
+ this.#check_size(2)
2507
+ var read
2508
+ if((endian != undefined ? endian : this.endian) == "little"){
2509
+ read = (this.data[this.offset + 1] << 8) | this.data[this.offset];
2510
+ } else {
2511
+ read = (this.data[this.offset] << 8) | this.data[this.offset + 1];
2512
+ }
2513
+ this.offset += 2
2514
+ if(unsigned == undefined || unsigned == false){
2515
+ return read
2516
+ } else {
2517
+ return read & 0xFFFF
2518
+ }
2519
+ }
2520
+
2521
+ /**
2522
+ * Read unsigned short
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
+ *
2535
+ * @returns number
2536
+ */
2537
+ readUInt16LE = this.uint16le = this.ushortle = this.uwordle = function(){
2538
+ return this.readInt16(true, "little")
2539
+ }
2540
+
2541
+ /**
2542
+ * Read signed short in little endian
2543
+ *
2544
+ * @returns number
2545
+ */
2546
+ readInt16LE = this.int16le = this.shortle = this.wordle = function(){
2547
+ return this.readInt16(false, "little")
2548
+ }
2549
+
2550
+ /**
2551
+ * Read unsigned short in big endian
2552
+ *
2553
+ * @returns number
2554
+ */
2555
+ readUInt16BE = this.uint16be = this.ushortbe = this.uwordbe = function(){
2556
+ return this.readInt16(true, "big")
2557
+ }
2558
+
2559
+ /**
2560
+ * Read signed short in big endian
2561
+ *
2562
+ * @returns number
2563
+ */
2564
+ readInt16BE = this.int16be = this.shortbe = this.wordbe = function(){
2565
+ return this.readInt16(false, "big")
2566
+ }
2567
+
2568
+ //
2569
+ //half float read
2570
+ //
2571
+
2572
+ /**
2573
+ * Read half float
2574
+ *
2575
+ * @param {string} endian - ```big``` or ```little```
2576
+ * @returns number
2577
+ */
2578
+ readHalfFloat = this.halffloat = this.half = function(endian){
2579
+ this.#check_size(2)
2580
+ var uint16Value;
2581
+ if((endian != undefined ? endian : this.endian) == "little"){
2582
+ uint16Value = this.readInt16LE(true)
2583
+ } else {
2584
+ uint16Value = this.readInt16BE(true)
2585
+ }
2586
+ const sign = (uint16Value & 0x8000) >> 15;
2587
+ const exponent = (uint16Value & 0x7C00) >> 10;
2588
+ const fraction = uint16Value & 0x03FF;
2589
+
2590
+ let floatValue;
2591
+
2592
+ if (exponent === 0) {
2593
+ if (fraction === 0) {
2594
+ floatValue = (sign === 0) ? 0 : -0; // +/-0
2595
+ } else {
2596
+ // Denormalized number
2597
+ floatValue = (sign === 0 ? 1 : -1) * Math.pow(2, -14) * (fraction / 0x0400);
2598
+ }
2599
+ } else if (exponent === 0x1F) {
2600
+ if (fraction === 0) {
2601
+ floatValue = (sign === 0) ? Number.POSITIVE_INFINITY : Number.NEGATIVE_INFINITY;
2602
+ } else {
2603
+ floatValue = Number.NaN;
2604
+ }
2605
+ } else {
2606
+ // Normalized number
2607
+ floatValue = (sign === 0 ? 1 : -1) * Math.pow(2, exponent - 15) * (1 + fraction / 0x0400);
2608
+ }
2609
+
2610
+ return floatValue;
2611
+ }
2612
+
2613
+ /**
2614
+ * Read half float
2615
+ *
2616
+ * @returns number
2617
+ */
2618
+ readHalfFloatBE = this.halffloatbe = this.halfbe = function(){
2619
+ return this.readHalfFloat("big")
2620
+ }
2621
+
2622
+ /**
2623
+ * Read half float
2624
+ *
2625
+ * @returns number
2626
+ */
2627
+ readHalfFloatLE = this.halffloatle = this.halfle = function(){
2628
+ return this.readHalfFloat("little")
2629
+ }
2630
+
2631
+ //
2632
+ //int read
2633
+ //
2634
+
2635
+ /**
2636
+ * Read 32 bit integer
2637
+ *
2638
+ * @param {boolean} unsigned - if value is unsigned or not
2639
+ * @param {string} endian - ```big``` or ```little```
2640
+ * @returns number
2641
+ */
2642
+ readInt32 = this.int = this.double = this.int32 = this.long = function(unsigned, endian){
2643
+ this.#check_size(4)
2644
+ var read;
2645
+ if((endian != undefined ? endian : this.endian) == "little"){
2646
+ read = ((this.data[this.offset + 3] << 24) | (this.data[this.offset + 2] << 16) | (this.data[this.offset + 1] << 8) | this.data[this.offset])
2647
+ } else {
2648
+ read = (this.data[this.offset] << 24) | (this.data[this.offset + 1] << 16) | (this.data[this.offset + 2] << 8) | this.data[this.offset + 3]
2649
+ }
2650
+ this.offset += 4
2651
+ if(unsigned == undefined || unsigned == false){
2652
+ return read
2653
+ } else {
2654
+ return read >>> 0
2655
+ }
2656
+ }
2657
+
2658
+ /**
2659
+ * Read unsigned 32 bit integer
2660
+ *
2661
+ * @returns number
2662
+ */
2663
+ readUInt = this.uint = this.udouble = this.uint32 = this.ulong = function(){
2664
+ return this.readInt32(true)
2665
+ }
2666
+
2667
+ /**
2668
+ * Read signed 32 bit integer
2669
+ *
2670
+ * @returns number
2671
+ */
2672
+ readInt32BE = this.intbe = this.doublebe = this.int32be = this.longbe = function(){
2673
+ return this.readInt32(false, "big")
2674
+ }
2675
+
2676
+ /**
2677
+ * Read unsigned 32 bit integer
2678
+ *
2679
+ * @returns number
2680
+ */
2681
+ readUInt32BE = this.uintbe = this.udoublebe = this.uint32be = this.ulongbe = function(){
2682
+ return this.readInt32(true, "big")
2683
+ }
2684
+
2685
+ /**
2686
+ * Read signed 32 bit integer
2687
+ *
2688
+ * @returns number
2689
+ */
2690
+ readInt32LE = this.intle = this.doublele = this.int32le = this.longle = function(){
2691
+ return this.readInt32(false, "little")
2692
+ }
2693
+
2694
+ /**
2695
+ * Read signed 32 bit integer
2696
+ *
2697
+ * @returns number
2698
+ */
2699
+ readUInt32LE = this.uintle = this.udoublele = this.uint32le = this.ulongle = function(){
2700
+ return this.readInt32(true, "little")
2701
+ }
2702
+
2703
+ //
2704
+ //float read
2705
+ //
2706
+
2707
+ /**
2708
+ * Read float
2709
+ *
2710
+ * @param {string} endian - ```big``` or ```little```
2711
+ * @returns number
2712
+ */
2713
+ readFloat = this.float = function(endian){
2714
+ this.#check_size(4)
2715
+ var uint32Value;
2716
+ if((endian == undefined ? this.endian : endian) == "little"){
2717
+ uint32Value = this.readUInt32LE()
2718
+ } else {
2719
+ uint32Value = this.readUInt32BE()
2720
+ }
2721
+ // Check if the value is negative (i.e., the most significant bit is set)
2722
+ const isNegative = (uint32Value & 0x80000000) !== 0;
2723
+
2724
+ // Extract the exponent and fraction parts
2725
+ const exponent = (uint32Value >> 23) & 0xFF;
2726
+ const fraction = uint32Value & 0x7FFFFF;
2727
+
2728
+ // Calculate the float value
2729
+ let floatValue;
2730
+
2731
+ if (exponent === 0) {
2732
+ // Denormalized number (exponent is 0)
2733
+ floatValue = Math.pow(-1, isNegative) * Math.pow(2, -126) * (fraction / Math.pow(2, 23));
2734
+ } else if (exponent === 0xFF) {
2735
+ // Infinity or NaN (exponent is 255)
2736
+ floatValue = fraction === 0 ? (isNegative ? Number.NEGATIVE_INFINITY : Number.POSITIVE_INFINITY) : Number.NaN;
2737
+ } else {
2738
+ // Normalized number
2739
+ floatValue = Math.pow(-1, isNegative) * Math.pow(2, exponent - 127) * (1 + fraction / Math.pow(2, 23));
2740
+ }
2741
+
2742
+ return floatValue;
2743
+ }
2744
+
2745
+ /**
2746
+ * Read float
2747
+ *
2748
+ * @returns number
2749
+ */
2750
+ readFloatBE = this.floatbe = function(){
2751
+ return this.readFloat("big")
2752
+ }
2753
+
2754
+ /**
2755
+ * Read float
2756
+ *
2757
+ * @returns number
2758
+ */
2759
+ readFloatLE = this.floatle = function(){
2760
+ return this.readFloat("little")
2761
+ }
2762
+
2763
+ //
2764
+ //int64 reader
2765
+ //
2766
+
2767
+ /**
2768
+ * Read signed 64 bit integer
2769
+ * @param {boolean} unsigned - if value is unsigned or not
2770
+ * @param {string} endian - ```big``` or ```little```
2771
+ * @returns number
2772
+ */
2773
+ readInt64 = this.int64 = this.bigint = this.quad = function(unsigned, endian) {
2774
+ this.#check_size(8)
2775
+
2776
+ // Convert the byte array to a BigInt
2777
+ let value = BigInt(0);
2778
+ if((endian == undefined ? this.endian : endian) == "little"){
2779
+ for (let i = 0; i < 8; i++) {
2780
+ value |= BigInt(this.data[this.offset]) << BigInt(8 * i);
2781
+ this.offset += 1
2782
+ }
2783
+ if(unsigned == undefined || unsigned == false){
2784
+ if (value & (BigInt(1) << BigInt(63))) {
2785
+ value -= BigInt(1) << BigInt(64);
2786
+ }
2787
+ return value;
2788
+ } else {
2789
+ return value;
2790
+ }
2791
+ } else {
2792
+ for (let i = 0; i < 8; i++) {
2793
+ value = (value << BigInt(8)) | BigInt(this.data[this.offset]);
2794
+ this.offset += 1
2795
+ }
2796
+ if(unsigned == undefined || unsigned == false){
2797
+ if (value & (BigInt(1) << BigInt(63))) {
2798
+ value -= BigInt(1) << BigInt(64);
2799
+ }
2800
+ return value;
2801
+ } else {
2802
+ return value;
2803
+ }
2804
+ }
2805
+ }
2806
+
2807
+ /**
2808
+ * Read unsigned 64 bit integer
2809
+ *
2810
+ * @returns number
2811
+ */
2812
+ readUInt64 = this.uint64 = this.ubigint = this.uquad = function() {
2813
+ return this.readInt64(true)
2814
+ }
2815
+
2816
+ /**
2817
+ * Read signed 64 bit integer
2818
+ *
2819
+ * @returns number
2820
+ */
2821
+ readInt64BE = this.int64be = this.bigintbe = this.quadbe = function() {
2822
+ return this.readInt64(false, "big")
2823
+ }
2824
+
2825
+ /**
2826
+ * Read unsigned 64 bit integer
2827
+ *
2828
+ * @returns number
2829
+ */
2830
+ readUInt64BE = this.uint64be = this.ubigintbe = this.uquadbe = function() {
2831
+ return this.readInt64(true, "big");
2832
+ }
2833
+
2834
+ /**
2835
+ * Read signed 64 bit integer
2836
+ *
2837
+ * @returns number
2838
+ */
2839
+ readInt64LE = this.int64le = this.bigintle = this.quadle = function() {
2840
+ return this.readInt64(false, "little")
2841
+ }
2842
+
2843
+ /**
2844
+ * Read unsigned 64 bit integer
2845
+ *
2846
+ * @returns number
2847
+ */
2848
+ readUInt64LE = this.uint64le = this.ubigintle = this.uquadle = function() {
2849
+ return this.readInt64(true, "little");
2850
+ }
2851
+
2852
+ //
2853
+ //doublefloat reader
2854
+ //
2855
+
2856
+ /**
2857
+ * Read double float
2858
+ *
2859
+ * @param {string} endian - ```big``` or ```little```
2860
+ * @returns number
2861
+ */
2862
+ readDoubleFloat = this.doublefloat = this.dfloat = function(endian){
828
2863
  this.#check_size(8)
829
- var uint64Value ;
830
- var endian = order == undefined ? this.endian : order
831
- if(endian == "little"){
832
- uint64Value = this.readInt64LE(true)
2864
+ var uint64Value;
2865
+ if((endian == undefined ? this.endian : endian) == "little"){
2866
+ uint64Value = this.readUInt64LE()
833
2867
  } else {
834
- uint64Value = this.readInt64BE(true)
2868
+ uint64Value = this.readUInt64BE()
835
2869
  }
836
2870
  const sign = (uint64Value & 0x8000000000000000n) >> 63n;
837
2871
  const exponent = Number((uint64Value & 0x7FF0000000000000n) >> 52n) - 1023;
@@ -860,54 +2894,448 @@ class bireader {
860
2894
  return floatValue;
861
2895
  }
862
2896
 
863
- /**
2897
+ /**
2898
+ * Read double float
2899
+ *
864
2900
  * @returns number
865
2901
  */
866
- doublefloat = function(){
867
- return this.readDoubleFloat()
2902
+ readDoubleFloatBE = this.dfloatebe = this.doublefloatbe = function(){
2903
+ return this.readDoubleFloat("big")
868
2904
  }
869
2905
 
870
2906
  /**
2907
+ * Read double float
2908
+ *
871
2909
  * @returns number
872
2910
  */
873
- doublefloatbe = function(){
874
- return this.readDoubleFloat(true)
2911
+ readDoubleFloatLE = this.dfloatle = this.doublefloatle = function(){
2912
+ return this.readDoubleFloat("little")
875
2913
  }
876
2914
 
877
- /**
878
- * @returns number
2915
+ //
2916
+ //string reader
2917
+ //
2918
+
2919
+ /**
2920
+ * Reads string, use options object for different types
2921
+ *
2922
+ * @param {object} options
2923
+ * ```javascript
2924
+ * {
2925
+ * length: number, //for fixed length, non-terminate value utf strings
2926
+ * stringType: "utf-8", //utf-8, utf-16, pascal or wide-pascal
2927
+ * terminateValue: 0x00, // only for non-fixed length utf strings
2928
+ * lengthReadSize: 1, //for pascal strings. 1, 2 or 4 byte length read size
2929
+ * stripNull: true, // removes 0x00 characters
2930
+ * encoding: "utf-8", //TextEncoder accepted types
2931
+ * endian: "little", //for wide-pascal and utf-16
2932
+ * }
2933
+ * ```
2934
+ * @return string
879
2935
  */
880
- doublefloatle = function(){
881
- return this.readDoubleFloat(false)
2936
+ readString = this.string = function(options = {}){
2937
+
2938
+ var {
2939
+ length = undefined,
2940
+ stringType = 'utf-8',
2941
+ terminateValue = undefined,
2942
+ lengthReadSize = 1,
2943
+ stripNull = true,
2944
+ encoding = undefined,
2945
+ endian = this.endian,
2946
+ } = options;
2947
+
2948
+ var terminate = terminateValue
2949
+
2950
+ if(length != undefined){
2951
+ this.#check_size(length)
2952
+ }
2953
+
2954
+ if(typeof terminateValue == "number"){
2955
+ terminate = terminateValue & 0xFF
2956
+ } else {
2957
+ if(terminateValue != undefined){
2958
+ throw new Error("terminateValue must be a number")
2959
+ }
2960
+ }
2961
+
2962
+ if (stringType == 'utf-8' || stringType == 'utf-16') {
2963
+
2964
+ if(encoding == undefined){
2965
+ if(stringType == 'utf-8'){
2966
+ encoding = 'utf-8'
2967
+ }
2968
+ if(stringType == 'utf-16'){
2969
+ encoding = 'utf-16'
2970
+ }
2971
+ }
2972
+
2973
+ // Read the string as UTF-8 encoded untill 0 or terminateValue
2974
+ const encodedBytes = [];
2975
+
2976
+ if(length == undefined && terminateValue == undefined){
2977
+ terminate = 0
2978
+ }
2979
+
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++) {
2989
+ if (stringType === 'utf-8') {
2990
+ var read = this.readUByte();
2991
+ if(read == terminate){
2992
+ break;
2993
+ } else {
2994
+ if(!(stripNull == true && read == 0)){
2995
+ encodedBytes.push(read);
2996
+ }
2997
+ }
2998
+ } else {
2999
+ var read = this.readInt16(true, endian);
3000
+ var read1 = read & 0xFF
3001
+ var read2 = (read >> 8) & 0xFF
3002
+ if(read == terminate){
3003
+ break;
3004
+ } else {
3005
+ if(!(stripNull == true && read == 0)){
3006
+ encodedBytes.push(read1);
3007
+ encodedBytes.push(read2);
3008
+ }
3009
+ }
3010
+ }
3011
+ }
3012
+
3013
+ return new TextDecoder(encoding).decode(new Uint8Array(encodedBytes));
3014
+
3015
+ } else if (stringType == 'pascal' || stringType == 'wide-pascal') {
3016
+
3017
+ if(encoding == undefined){
3018
+ if(stringType == 'pascal'){
3019
+ encoding = 'utf-8'
3020
+ }
3021
+ if(stringType == 'wide-pascal'){
3022
+ encoding = 'utf-16'
3023
+ }
3024
+ }
3025
+
3026
+ var maxBytes;
3027
+ if(lengthReadSize == 1){
3028
+ maxBytes = this.readUByte();
3029
+ } else if(lengthReadSize == 2){
3030
+ maxBytes = this.readInt16(true, endian);
3031
+ } else if(lengthReadSize == 4){
3032
+ maxBytes = this.readInt32(true, endian);
3033
+ } else {
3034
+ throw new Error("Invalid length read size: " + lengthReadSize)
3035
+ }
3036
+
3037
+ // Read the string as Pascal or Delphi encoded
3038
+ const encodedBytes = [];
3039
+ for (let i = 0; i < maxBytes; i++) {
3040
+ if (stringType == 'wide-pascal') {
3041
+ const read = this.readInt16(true, endian)
3042
+ if(!(stripNull == true && read == 0)){
3043
+ encodedBytes.push(read)
3044
+ }
3045
+ } else {
3046
+ const read = this.readUByte()
3047
+ if(!(stripNull == true && read == 0)){
3048
+ encodedBytes.push(read)
3049
+ }
3050
+ }
3051
+ }
3052
+ var str_return
3053
+ if(stringType == 'wide-pascal'){
3054
+ str_return = new TextDecoder(encoding).decode(new Uint16Array(encodedBytes));
3055
+ } else {
3056
+ str_return = new TextDecoder(encoding).decode(new Uint8Array(encodedBytes));
3057
+ }
3058
+
3059
+ return str_return
3060
+ } else {
3061
+ throw new Error('Unsupported string type: '+ stringType);
3062
+ }
882
3063
  }
883
3064
 
884
3065
  /**
885
- * @returns number
3066
+ * Reads UTF-8 (C) string
3067
+ *
3068
+ * @param {number} length - for fixed length utf strings
3069
+ * @param {number} terminateValue - for non-fixed length utf strings
3070
+ * @param {boolean} stripNull - removes 0x00 characters
3071
+ *
3072
+ * @return string
886
3073
  */
887
- readDoubleFloatBE = function(){
888
- return this.readDoubleFloat(true)
3074
+ utf8string = this.cstring = function(length, terminateValue, stripNull){
3075
+ return this.string({stringType: "utf-8", encoding: "utf-8", length: length, terminateValue: terminateValue, stripNull: stripNull})
889
3076
  }
890
3077
 
891
3078
  /**
892
- * @returns number
3079
+ * Reads ANSI string
3080
+ *
3081
+ * @param {number} length - for fixed length utf strings
3082
+ * @param {number} terminateValue - for non-fixed length utf strings
3083
+ * @param {boolean} stripNull - removes 0x00 characters
3084
+ *
3085
+ * @return string
893
3086
  */
894
- readDoubleFloatLE = function(){
895
- return this.readDoubleFloat(false)
3087
+ ansistring = function(length, terminateValue, stripNull){
3088
+ return this.string({stringType: "utf-8", encoding: "windows-1252", length: length, terminateValue: terminateValue, stripNull: stripNull})
896
3089
  }
897
-
3090
+
898
3091
  /**
899
- * removes reading data
3092
+ * Reads UTF-16 (Unicode) string
3093
+ *
3094
+ * @param {number} length - for fixed length utf strings
3095
+ * @param {number} terminateValue - for non-fixed length utf strings
3096
+ * @param {boolean} stripNull - removes 0x00 characters
3097
+ * @param {string} endian - ``big`` or ``little``
3098
+ *
3099
+ * @return string
900
3100
  */
901
- end = function(){
902
- this.data = []
3101
+ utf16string = this.unistring = function(length, terminateValue, stripNull, endian){
3102
+ return this.string({stringType: "utf-16", encoding: "utf-16", length: length, terminateValue: terminateValue, endian: endian, stripNull: stripNull})
903
3103
  }
904
3104
 
905
3105
  /**
906
- * removes reading data
3106
+ * Reads UTF-16 (Unicode) string in little endian order
3107
+ *
3108
+ * @param {number} length - for fixed length utf strings
3109
+ * @param {number} terminateValue - for non-fixed length utf strings
3110
+ * @param {boolean} stripNull - removes 0x00 characters
3111
+ *
3112
+ * @return string
3113
+ */
3114
+ utf16stringle = this.unistringle = function(length, terminateValue, stripNull){
3115
+ return this.string({stringType: "utf-16", encoding: "utf-16", length: length, terminateValue: terminateValue, endian: "little", stripNull: stripNull})
3116
+ }
3117
+
3118
+ /**
3119
+ * Reads UTF-16 (Unicode) string in big endian order
3120
+ *
3121
+ * @param {number} length - for fixed length utf strings
3122
+ * @param {number} terminateValue - for non-fixed length utf strings
3123
+ * @param {boolean} stripNull - removes 0x00 characters
3124
+ *
3125
+ * @return string
3126
+ */
3127
+ utf16stringbe = this.unistringbe = function(length, terminateValue, stripNull){
3128
+ return this.string({stringType: "utf-16", encoding: "utf-16", length: length, terminateValue: terminateValue, endian: "big", stripNull: stripNull})
3129
+ }
3130
+
3131
+ /**
3132
+ * Reads Pascal string
3133
+ *
3134
+ * @param {number} lengthReadSize - 1, 2 or 4 byte length write size (default 1)
3135
+ * @param {boolean} stripNull - removes 0x00 characters
3136
+ * @param {string} endian - ``big`` or ``little``
3137
+ *
3138
+ * @return string
3139
+ */
3140
+ pstring = function(lengthReadSize, stripNull, endian){
3141
+ return this.string({stringType: "pascal", encoding: "utf-8", lengthReadSize: lengthReadSize, stripNull: stripNull, endian: endian})
3142
+ }
3143
+
3144
+ /**
3145
+ * Reads Pascal string 1 byte length read
3146
+ *
3147
+ * @param {boolean} stripNull - removes 0x00 characters
3148
+ * @param {string} endian - ``big`` or ``little``
3149
+ *
3150
+ * @return string
3151
+ */
3152
+ pstring1 = function(stripNull, endian){
3153
+ return this.string({stringType: "pascal", encoding: "utf-8", lengthReadSize: 1, stripNull: stripNull, endian: endian})
3154
+ }
3155
+
3156
+ /**
3157
+ * Reads Pascal string 1 byte length read in little endian order
3158
+ *
3159
+ * @param {boolean} stripNull - removes 0x00 characters
3160
+ *
3161
+ * @return string
3162
+ */
3163
+ pstring1le = function(stripNull){
3164
+ return this.string({stringType: "pascal", encoding: "utf-8", lengthReadSize: 1, stripNull: stripNull, endian: "little"})
3165
+ }
3166
+
3167
+ /**
3168
+ * Reads Pascal string 1 byte length read in big endian order
3169
+ *
3170
+ * @param {boolean} stripNull - removes 0x00 characters
3171
+ *
3172
+ * @return string
3173
+ */
3174
+ pstring1be = function(stripNull){
3175
+ return this.string({stringType: "pascal", encoding: "utf-8", lengthReadSize: 1, stripNull: stripNull, endian: "big"})
3176
+ }
3177
+
3178
+ /**
3179
+ * Reads Pascal string 2 byte length read
3180
+ *
3181
+ * @param {boolean} stripNull - removes 0x00 characters
3182
+ * @param {string} endian - ``big`` or ``little``
3183
+ *
3184
+ * @return string
3185
+ */
3186
+ pstring2 = function(stripNull, endian){
3187
+ return this.string({stringType: "pascal", encoding: "utf-8", lengthReadSize: 2, stripNull: stripNull, endian: endian})
3188
+ }
3189
+
3190
+ /**
3191
+ * Reads Pascal string 2 byte length read in little endian order
3192
+ *
3193
+ * @param {boolean} stripNull - removes 0x00 characters
3194
+ *
3195
+ * @return string
3196
+ */
3197
+ pstring2le = function(stripNull){
3198
+ return this.string({stringType: "pascal", encoding: "utf-8", lengthReadSize: 2, stripNull: stripNull, endian: "little"})
3199
+ }
3200
+
3201
+ /**
3202
+ * Reads Pascal string 2 byte length read in big endian order
3203
+ *
3204
+ * @param {boolean} stripNull - removes 0x00 characters
3205
+ *
3206
+ * @return string
3207
+ */
3208
+ pstring2be = function(stripNull){
3209
+ return this.string({stringType: "pascal", encoding: "utf-8", lengthReadSize: 2, stripNull: stripNull, endian: "big"})
3210
+ }
3211
+
3212
+ /**
3213
+ * Reads Pascal string 4 byte length read
3214
+ *
3215
+ * @param {boolean} stripNull - removes 0x00 characters
3216
+ * @param {string} endian - ``big`` or ``little``
3217
+ *
3218
+ * @return string
3219
+ */
3220
+ pstring4 = function(stripNull, endian){
3221
+ return this.string({stringType: "pascal", encoding: "utf-8", lengthReadSize: 4, stripNull: stripNull, endian: endian})
3222
+ }
3223
+
3224
+ /**
3225
+ * Reads Pascal string 4 byte length read in little endian order
3226
+ *
3227
+ * @param {boolean} stripNull - removes 0x00 characters
3228
+ *
3229
+ * @return string
3230
+ */
3231
+ pstring4le = function(stripNull){
3232
+ return this.string({stringType: "pascal", encoding: "utf-8", lengthReadSize: 4, stripNull: stripNull, endian: "little"})
3233
+ }
3234
+
3235
+ /**
3236
+ * Reads Pascal string 4 byte length read in big endian order
3237
+ *
3238
+ * @param {boolean} stripNull - removes 0x00 characters
3239
+ *
3240
+ * @return string
3241
+ */
3242
+ pstring4be = function(stripNull){
3243
+ return this.string({stringType: "pascal", encoding: "utf-8", lengthReadSize: 4, stripNull: stripNull, endian: "big"})
3244
+ }
3245
+
3246
+ /**
3247
+ * Reads Wide-Pascal string
3248
+ *
3249
+ * @param {number} lengthReadSize - 1, 2 or 4 byte length write size (default 1)
3250
+ * @param {boolean} stripNull - removes 0x00 characters
3251
+ * @param {string} endian - ``big`` or ``little``
3252
+ *
3253
+ * @return string
3254
+ */
3255
+ wpstring = function(lengthReadSize, stripNull, endian){
3256
+ return this.string({stringType: "wide-pascal", encoding: "utf-16", lengthReadSize: lengthReadSize, endian: endian, stripNull: stripNull})
3257
+ }
3258
+
3259
+ /**
3260
+ * Reads Wide-Pascal string 1 byte length read
3261
+ *
3262
+ * @param {boolean} stripNull - removes 0x00 characters
3263
+ * @param {string} endian - ``big`` or ``little``
3264
+ *
3265
+ * @return string
3266
+ */
3267
+ wpstring1 = function(stripNull, endian){
3268
+ return this.string({stringType: "wide-pascal", encoding: "utf-16", lengthReadSize: 1, endian: endian, stripNull: stripNull})
3269
+ }
3270
+
3271
+ /**
3272
+ * Reads Wide-Pascal string 2 byte length read
3273
+ *
3274
+ * @param {boolean} stripNull - removes 0x00 characters
3275
+ * @param {string} endian - ``big`` or ``little``
3276
+ *
3277
+ * @return string
3278
+ */
3279
+ wpstring2 = function(stripNull, endian){
3280
+ return this.string({stringType: "wide-pascal", encoding: "utf-16", lengthReadSize: 2, endian: endian, stripNull: stripNull})
3281
+ }
3282
+
3283
+ /**
3284
+ * Reads Wide-Pascal string 2 byte length read in little endian order
3285
+ *
3286
+ * @param {boolean} stripNull - removes 0x00 characters
3287
+ *
3288
+ * @return string
3289
+ */
3290
+ wpstring2le = function(stripNull){
3291
+ return this.string({stringType: "wide-pascal", encoding: "utf-16", lengthReadSize: 2, endian: "little", stripNull: stripNull})
3292
+ }
3293
+
3294
+ /**
3295
+ * Reads Wide-Pascal string 2 byte length read in big endian order
3296
+ *
3297
+ * @param {boolean} stripNull - removes 0x00 characters
3298
+ *
3299
+ * @return string
3300
+ */
3301
+ wpstring2be = function(stripNull){
3302
+ return this.string({stringType: "wide-pascal", encoding: "utf-16", lengthReadSize: 2, endian: "big", stripNull: stripNull})
3303
+ }
3304
+
3305
+ /**
3306
+ * Reads Wide-Pascal string 4 byte length read
3307
+ *
3308
+ * @param {boolean} stripNull - removes 0x00 characters
3309
+ * @param {string} endian - ``big`` or ``little``
3310
+ *
3311
+ * @return string
3312
+ */
3313
+ wpstring4 = function(stripNull, endian){
3314
+ return this.string({stringType: "wide-pascal", encoding: "utf-16", lengthReadSize: 4, endian: endian, stripNull: stripNull})
3315
+ }
3316
+
3317
+ /**
3318
+ * Reads Wide-Pascal string 4 byte length read in big endian order
3319
+ *
3320
+ * @param {boolean} stripNull - removes 0x00 characters
3321
+ *
3322
+ * @return string
3323
+ */
3324
+ wpstring4be = function(stripNull){
3325
+ return this.string({stringType: "wide-pascal", encoding: "utf-16", lengthReadSize: 4, endian: "big", stripNull: stripNull})
3326
+ }
3327
+
3328
+ /**
3329
+ * Reads Wide-Pascal string 4 byte length read in little endian order
3330
+ *
3331
+ * @param {boolean} stripNull - removes 0x00 characters
3332
+ *
3333
+ * @return string
907
3334
  */
908
- close = function(){
909
- this.data = []
3335
+ wpstring4le = function(stripNull){
3336
+ return this.string({stringType: "wide-pascal", encoding: "utf-16", lengthReadSize: 4, endian: "little", stripNull: stripNull})
910
3337
  }
3338
+
911
3339
  }
912
3340
 
913
3341
  module.exports = bireader