@@ -5,14 +5,6 @@ module.exports = class BufferReader {
5
5
assert ( Buffer . isBuffer ( buffer ) , 'Invalid buffer.' ) ;
6
6
this . buffer = buffer ;
7
7
this . offset = 0 ;
8
- this . _makeNextReadFor ( 'Int8' , 1 ) ;
9
- this . _makeNextReadFor ( 'UInt8' , 1 ) ;
10
- this . _makeNextReadLEBEFor ( 'UInt16' , 2 ) ;
11
- this . _makeNextReadLEBEFor ( 'Int16' , 2 ) ;
12
- this . _makeNextReadLEBEFor ( 'UInt32' , 4 ) ;
13
- this . _makeNextReadLEBEFor ( 'Int32' , 4 ) ;
14
- this . _makeNextReadLEBEFor ( 'Float' , 4 ) ;
15
- this . _makeNextReadLEBEFor ( 'Double' , 8 ) ;
16
8
}
17
9
18
10
seek ( offset , fromBeginning = true ) {
@@ -24,6 +16,62 @@ module.exports = class BufferReader {
24
16
this . offset = offset ;
25
17
}
26
18
19
+ nextDoubleLE ( ) {
20
+ return this . _nextXX ( 'DoubleLE' , 8 ) ;
21
+ }
22
+
23
+ nextDoubleBE ( ) {
24
+ return this . _nextXX ( 'DoubleBE' , 8 ) ;
25
+ }
26
+
27
+ nextFloatLE ( ) {
28
+ return this . _nextXX ( 'FloatLE' , 4 ) ;
29
+ }
30
+
31
+ nextFloatBE ( ) {
32
+ return this . _nextXX ( 'FloatBE' , 4 ) ;
33
+ }
34
+
35
+ nextInt32LE ( ) {
36
+ return this . _nextXX ( 'Int32LE' , 4 ) ;
37
+ }
38
+
39
+ nextInt32BE ( ) {
40
+ return this . _nextXX ( 'Int32BE' , 4 ) ;
41
+ }
42
+
43
+ nextUInt32LE ( ) {
44
+ return this . _nextXX ( 'UInt32LE' , 4 ) ;
45
+ }
46
+
47
+ nextUInt32BE ( ) {
48
+ return this . _nextXX ( 'UInt32BE' , 4 ) ;
49
+ }
50
+
51
+ nextUInt16LE ( ) {
52
+ return this . _nextXX ( 'UInt16LE' , 2 ) ;
53
+ }
54
+
55
+ nextUInt16BE ( ) {
56
+ return this . _nextXX ( 'UInt16BE' , 2 ) ;
57
+ }
58
+
59
+ nextInt16LE ( ) {
60
+ return this . _nextXX ( 'Int16LE' , 2 ) ;
61
+ }
62
+
63
+ nextInt16BE ( ) {
64
+ return this . _nextXX ( 'Int16BE' , 2 ) ;
65
+ }
66
+
67
+ nextUInt8 ( ) {
68
+ return this . _nextXX ( 'UInt8' , 1 ) ;
69
+ }
70
+
71
+ nextInt8 ( ) {
72
+ return this . _nextXX ( 'Int8' , 1 ) ;
73
+ }
74
+
27
75
nextBuffer ( length ) {
28
76
this . _checkPositive ( length ) ;
29
77
this . _checkOffsetInRange ( this . offset + length ) ;
@@ -42,18 +90,12 @@ module.exports = class BufferReader {
42
90
return str ;
43
91
}
44
92
45
- _makeNextReadLEBEFor ( method , size ) {
46
- this . _makeNextReadFor ( method + 'LE' , size ) ;
47
- this . _makeNextReadFor ( method + 'BE' , size ) ;
48
- }
93
+ _nextXX ( type , size ) {
94
+ this . _checkOffsetInRange ( this . offset + size , 'Offset' ) ;
49
95
50
- _makeNextReadFor ( method , size ) {
51
- BufferReader . prototype [ `next${ method } ` ] = function ( ) {
52
- this . _checkOffsetInRange ( this . offset + size , 'Offset' ) ;
53
- const val = this . buffer [ `read${ method } ` ] ( this . offset ) ;
54
- this . offset += size ;
55
- return val ;
56
- } ;
96
+ const v = this . buffer [ `read${ type } ` ] ( this . offset ) ;
97
+ this . offset += size ;
98
+ return v ;
57
99
}
58
100
59
101
_checkPositive ( number , name = 'Length' ) {
0 commit comments