diff --git a/src/me/topchetoeu/jscript/filesystem/File.java b/src/me/topchetoeu/jscript/filesystem/File.java index 6e7f24a..f6e625a 100644 --- a/src/me/topchetoeu/jscript/filesystem/File.java +++ b/src/me/topchetoeu/jscript/filesystem/File.java @@ -1,41 +1,41 @@ -package me.topchetoeu.jscript.filesystem; - -import me.topchetoeu.jscript.Buffer; - -public interface File { - int read(byte[] buff); - void write(byte[] buff); - long getPtr(); - void setPtr(long offset, int pos); - void close(); - Mode mode(); - - default String readToString() { - setPtr(0, 2); - long len = getPtr(); - if (len < 0) return null; - - setPtr(0, 0); - - byte[] res = new byte[(int)len]; - read(res); - - return new String(res); - } - default String readLine() { - var res = new Buffer(); - var buff = new byte[1]; - - while (true) { - if (read(buff) == 0) { - if (res.length() == 0) return null; - else break; - } - - if (buff[0] == '\n') break; - - res.write(res.length(), buff); - } - return new String(res.data()); - } +package me.topchetoeu.jscript.filesystem; + +import me.topchetoeu.jscript.Buffer; + +public interface File { + int read(byte[] buff); + void write(byte[] buff); + long getPtr(); + void setPtr(long offset, int pos); + void close(); + Mode mode(); + + default String readToString() { + setPtr(0, 2); + long len = getPtr(); + if (len < 0) return null; + + setPtr(0, 0); + + byte[] res = new byte[(int)len]; + len = read(res); + + return new String(res); + } + default String readLine() { + var res = new Buffer(); + var buff = new byte[1]; + + while (true) { + if (read(buff) == 0) { + if (res.length() == 0) return null; + else break; + } + + if (buff[0] == '\n') break; + + res.write(res.length(), buff); + } + return new String(res.data()); + } } \ No newline at end of file diff --git a/src/me/topchetoeu/jscript/filesystem/PhysicalFile.java b/src/me/topchetoeu/jscript/filesystem/PhysicalFile.java index 5fba05e..0514e0e 100644 --- a/src/me/topchetoeu/jscript/filesystem/PhysicalFile.java +++ b/src/me/topchetoeu/jscript/filesystem/PhysicalFile.java @@ -35,9 +35,9 @@ public class PhysicalFile implements File { if (file == null || !perms.readable) throw new FilesystemException(filename, FSCode.NO_PERMISSIONS_R); try { - if (pos == 1) pos += file.getFilePointer(); - else if (pos == 2) pos += file.length(); - file.seek(pos); + if (pos == 1) offset += file.getFilePointer(); + else if (pos == 2) offset += file.length(); + file.seek(offset); } catch (IOException e) { throw new FilesystemException(filename, FSCode.NO_PERMISSIONS_R); } }