# Open the same file again.
# The original path is reused, therefore the reopened file can be a different file.
+ #
+ # var f = new FileReader.open("/etc/issue")
+ # var l = f.read_line
+ # f.reopen
+ # assert l == f.read_line
fun reopen
do
if not eof and not _file.address_is_null then close
redef var end_reached: Bool = false
# Open the file at `path` for reading.
+ #
+ # var f = new FileReader.open("/etc/issue")
+ # assert not f.end_reached
+ # f.close
+ #
+ # In case of error, `last_error` is set
+ #
+ # f = new FileReader.open("/fail/does not/exist")
+ # assert f.end_reached
+ # assert f.last_error != null
init open(path: String)
do
self.path = path
end
end
+ # Creates a new File stream from a file descriptor
+ #
+ # This is a low-level method.
init from_fd(fd: Int) do
self.path = ""
prepare_buffer(1)
###############################################################################
# Standard input stream.
+#
+# The class of the default value of `sys.stdin`.
class Stdin
super FileReader
end
# Standard output stream.
+#
+# The class of the default value of `sys.stdout`.
class Stdout
super FileWriter
init do
end
# Standard error stream.
+#
+# The class of the default value of `sys.stderr`.
class Stderr
super FileWriter
init do
end
# Delete a file from the file system, return `true` on success
- #
- # Require: `exists`
fun delete: Bool do return path.to_cstring.file_delete
# Copy content of file at `path` to `dest`
end
# Simplify a file path by remove useless ".", removing "//", and resolving ".."
- # ".." are not resolved if they start the path
- # starting "/" is not removed
- # trainling "/" is removed
#
- # Note that the method only wonrk on the string:
+ # * ".." are not resolved if they start the path
+ # * starting "/" is not removed
+ # * trailing "/" is removed
+ #
+ # Note that the method only work on the string:
#
# * no I/O access is performed
# * the validity of the path is not checked
# Using a standard "{self}/{path}" does not work in the following cases:
#
# * `self` is empty.
- # * `path` ends with `'/'`.
# * `path` starts with `'/'`.
#
# This method ensures that the join is valid.