Skip to content

Commit

Permalink
Fix behaviour of FileInput.eof()
Browse files Browse the repository at this point in the history
Used the c# implementation for reference, now it passes the sys tests
in the compiler repository
  • Loading branch information
tobil4sk committed Sep 25, 2021
1 parent d5f67f4 commit ee1dac8
Showing 1 changed file with 14 additions and 9 deletions.
23 changes: 14 additions & 9 deletions src/sys/io/FileInput.hx
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,12 @@ import js.node.Fs;
class FileInput extends haxe.io.Input {
var fd:Int;
var pos:Int;
var _eof = false;

private inline function _reachedEof():Void {
_eof = true;
throw new Eof();
}

@:allow(sys.io.File)
function new(fd:Int) {
Expand All @@ -23,12 +29,11 @@ class FileInput extends haxe.io.Input {
Fs.readSync(fd, buf, 0, 1, pos);
} catch (e:Dynamic) {
if (e.code == "EOF")
throw new Eof();
else
throw Error.Custom(e);
_reachedEof();
throw Error.Custom(e);
}
if (bytesRead == 0)
throw new Eof();
_reachedEof();
pos++;
return buf[0];
}
Expand All @@ -39,12 +44,11 @@ class FileInput extends haxe.io.Input {
Fs.readSync(fd, buf, pos, len, this.pos);
} catch (e:Dynamic) {
if (e.code == "EOF")
throw new Eof();
else
throw Error.Custom(e);
_reachedEof();
throw Error.Custom(e);
}
if (bytesRead == 0)
throw new Eof();
_reachedEof();
this.pos += bytesRead;
return bytesRead;
}
Expand All @@ -54,6 +58,7 @@ class FileInput extends haxe.io.Input {
}

public function seek(p:Int, pos:FileSeek):Void {
_eof = false;
switch (pos) {
case SeekBegin:
this.pos = p;
Expand All @@ -69,6 +74,6 @@ class FileInput extends haxe.io.Input {
}

public function eof():Bool {
return pos >= Fs.fstatSync(fd).size;
return _eof;
}
}

0 comments on commit ee1dac8

Please sign in to comment.