core :: FileStream :: defaultinit
# `Stream` used to interact with a File or FileDescriptor
abstract class FileStream
super Stream
# The path of the file.
var path: nullable String = null
# The FILE *.
private var file: nullable NativeFile = null
# The status of a file. see POSIX stat(2).
#
# var f = new FileReader.open("/etc/issue")
# assert f.file_stat.is_file
#
# Return null in case of error
fun file_stat: nullable FileStat
do
var stat = _file.as(not null).file_stat
if stat.address_is_null then return null
return new FileStat(stat)
end
# File descriptor of this file
fun fd: Int do return _file.as(not null).fileno
redef fun close
do
var file = _file
if file == null then return
if file.address_is_null then
if last_error != null then return
last_error = new IOError("Cannot close unopened file")
return
end
var i = file.io_close
if i != 0 then
last_error = new IOError("Close failed due to error {sys.errno.strerror}")
end
_file = null
end
# Sets the buffering mode for the current FileStream
#
# If the buf_size is <= 0, its value will be 512 by default
#
# The mode is any of the buffer_mode enumeration in `Sys`:
#
# * `buffer_mode_full`
# * `buffer_mode_line`
# * `buffer_mode_none`
fun set_buffering_mode(buf_size, mode: Int) do
if buf_size <= 0 then buf_size = 512
if _file.as(not null).set_buffering_type(buf_size, mode) != 0 then
last_error = new IOError("Error while changing buffering type for FileStream, returned error {sys.errno.strerror}")
end
end
end
lib/core/file.nit:43,1--99,3