File I/O Prototype

Children of the file IO prototype object ($core.file_io_proto) represent files. File objects are garbage collected (and automatically closed) when no longer used (in other words, you don't have to explicitly worry about management and there's no chance of file handle leakage).

See File Utilities for details how to open/read/write files.


none file:close()

Explicitly closes this file.

is_open is_closed

INT file:is_open()
INT file:is_closed()

Returns true if file is open/closed.

is_text is_binary

INT file:is_text()
INT file:is_binary()

Returns true if file was opened in text/binary mode.

is_readable is_writeable

INT file:is_readable()
INT file:is_writeable()

Returns true if file was opened for reading/writing.

readline writeline read write

STR file:readline()
none file:writeline(STR line)
STR file:read(INT number)
INT file:write(STR data)

Reads/writes from/to the specified file.

The read() verb reads up to the specified number of bytes from the file and returns them.

The write() verb writes the specified data to the file and returns the number of bytes written.

f:readline()          => "foobar"
f:write("~0A~0D")     => 2

tell seek size

INT file:size()
INT file:tell()
none file:seek(INT location, STR whence)

The size() verb returns the size of file.

The tell() verb returns the current position in file.

The seek() verb seeks to a position in file. whence is one of: "SEEK_SET" - seek relative to beginning, "SEEK_CUR" - seek relative to current position, "SEEK_END" - seek relative to end.

f:seek(0, "SEEK_END")     => _


INT file:is_eof()

Returns true if file is at end of file.