@@ -14,71 +14,46 @@ class FileReader {
1414
1515 #if js
1616 // js read file in once for better performance
17- var memBytes : haxe.io. Bytes ;
18- var memPos : Int ;
17+ var memInput : haxe.io. BytesInput ;
1918 #else
2019 var memInput : sys.io. FileInput ;
2120 #end
2221
2322 public inline function new (file : String ) {
2423 #if js
25- memBytes = sys.io. File .getBytes (file );
26- memPos = 0 ;
24+ memInput = new haxe.io. BytesInput (sys.io. File .getBytes (file ));
2725 #else
2826 memInput = sys.io. File .read (file );
2927 #end
3028 }
3129
3230 public inline function close () {
33- #if js
34- memBytes = null ;
35- memPos = 0 ;
36- #else
3731 if ( memInput != null )
3832 memInput .close ();
3933 memInput = null ;
40- #end
4134 }
4235
4336 public inline function readString (length : Int ) : String {
44- #if js
45- var str = memBytes .getString (memPos , 3 );
46- memPos + = 3 ;
47- #else
48- var str = memInput .read (3 ).toString ();
49- #end
50- return str ;
37+ return memInput .readString (length );
5138 }
5239
5340 public inline function readByte () : Int {
54- #if js
55- var b = memBytes .get (memPos );
56- memPos + = 1 ;
57- #else
58- var b = memInput .readByte ();
59- #end
60- return b ;
41+ return memInput .readByte ();
6142 }
6243
6344 public inline function readInt32 () : Int {
64- #if js
65- var i = memBytes .getInt32 (memPos );
66- memPos + = 4 ;
67- #else
68- var i = memInput .readInt32 ();
69- #end
70- return i ;
45+ return memInput .readInt32 ();
7146 }
7247
73- public inline function readPointer ( is64 : Bool ) : Block . Pointer {
48+ public inline function readPointer ( is64 : Bool ) : haxe. Int64 {
7449 var low = readInt32 ();
7550 var high = is64 ? readInt32 () : 0 ;
76- return cast haxe. Int64 .make (high ,low );
51+ return haxe. Int64 .make (high ,low );
7752 }
7853
7954 public inline function tell () : Float {
8055 #if js
81- return memPos ;
56+ return memInput . position ;
8257 #else
8358 return tell2 (@:privateAccess memInput .__f );
8459 #end
@@ -96,11 +71,11 @@ class FileReader {
9671 var dpos = Std .int (pos );
9772 switch ( mode ) {
9873 case SeekBegin :
99- memPos = dpos ;
74+ memInput . position = dpos ;
10075 case SeekCur :
101- memPos + = dpos ;
76+ memInput . position + = dpos ;
10277 case SeekEnd :
103- memPos = memBytes .length + dpos ;
78+ memInput . position = memInput .length + dpos ;
10479 }
10580 #else
10681 if ( ! seek2 (@:privateAccess memInput .__f , pos , mode .getIndex ()) )
0 commit comments