io

This module is dedicated to input/output operations.

Functions

print(...)

This function prints one or more values directly to stdout. Each value is first converted to a string and then output. A space is used as a separator between each value.

ArgumentDescription
...A list of values to print

open(path, flags)

Opens a file and returns an object that can be used to do I/O on that file.

ArgumentDescription
pathThe path to the file to open
flagsThe open flags, os/context dependent, such as "w", "r", "w+", ...

Returns: A valid descriptor or null

close(file)

Closes a file that was previously open.

ArgumentDescription
fileA file descriptor returned by open

Returns: true on success, false otherwise

read(file, [bytes])

Reads data from a file.

ArgumentDescription
fileA file descriptor returned by open
bytes   OptionalThe maximum number of bytes to read

Returns: true on success, false otherwise

write(file, data)

Writes data to a file descriptor.

ArgumentDescription
fileA file descriptor returned by open
dataA string with the data to be written

Returns: true on success, false otherwise

flush(file)

Flushes the buffer for a file, writing any pending changes immediately.

ArgumentDescription
fileA file descriptor returned by open

Returns: true on success, false otherwise

tell(file)

Gets the current position inside a file

ArgumentDescription
fileA file descriptor returned by open

Returns: The number of bytes into the file

seek(file, offset, [fromEnd])

Seeks the current position inside the file to a given value

ArgumentDescription
fileA file descriptor returned by open
offsetAn integer with the new offset in bytes
fromEnd   OptionalIf true sets the new position counting from the end of the file

Returns: true on success, false otherwise

size(file)

Returns the size of a given open file descriptor.

ArgumentDescription
fileA file descriptor returned by open

Returns: The number of total bytes for the file

isEOF(file)

Checks if the end of file has been reached for a file descriptor.

ArgumentDescription
fileA file descriptor returned by open

Returns: true if the EOF has been reached, false otherwise

Properties

stdin

The standard input file

stdout

The standard output file

stderr

The standard error file