redef fun close
do
- if _file.address_is_null then return
+ if _file == null or _file.address_is_null then return
var i = _file.io_close
_buffer.clear
end_reached = true
+ _file = null
end
redef fun fill_buffer
redef fun close
do
+ if _file == null then return
if _file.address_is_null then
if last_error != null then return
last_error = new IOError("Cannot close unopened write stream")
last_error = new IOError("Close failed due to error {sys.errno.strerror}")
end
_is_writable = false
+ _file = null
end
redef var is_writable = false
# Read all the content of the file
#
+ # ~~~
+ # var content = "/etc/issue".to_path.read_all
+ # print content
+ # ~~~
+ #
# See `IStream::read_all` for details.
fun read_all: String
do
# Read all the lines of the file
#
+ # ~~~
+ # var lines = "/etc/passwd".to_path.read_lines
+ #
+ # print "{lines.length} users"
+ #
+ # for l in lines do
+ # var fields = l.split(":")
+ # print "name={fields[0]} uid={fields[2]}"
+ # end
+ # ~~~
+ #
# See `IStream::read_lines` for details.
fun read_lines: Array[String]
do
end
# Return an iterator on each line of the file
+ #
+ # ~~~
+ # for l in "/etc/passwd".to_path.each_line do
+ # var fields = l.split(":")
+ # print "name={fields[0]} uid={fields[2]}"
+ # end
+ # ~~~
+ #
# Note: the stream is automatically closed at the end of the file (see `LineIterator::close_on_finish`)
#
# See `IStream::each_line` for details.