io¶
This module provies access to high i/o primitives and streams.
File object¶
-
class
io.File()¶ Class representing a stdio stream.
This class created through
io.open()orio.fdopen(), never directly.
-
io.File.path¶ Returns the opened file’s path.
-
io.File.fd¶ Returns the file descriptor associated with the file.
-
io.File.mode¶ Returns the mode in which the file was opened.
-
io.File.closed¶ Boolean flag indicating if the file was closed.
-
io.FIle.prototype.read(nread)¶ Read data from the file.
Arguments: - nread – Amount of data to receive. If not specified it defaults to 4096. Alternatively, a Buffer can be passed, and data will be read into it.
Returns: The data that was read as a Uint8Array or the amount of data read as a number, if a Buffer was passed.
See also
-
io.FIle.prototype.readLine(nread)¶ Similar to
io.FIle.prototype.read(), but stops at the newline (\n) character. This is the recommended function to read from stdin, but not from binary files.See also
-
io.FIle.prototype.write(data)¶ Write data on the file.
Arguments: - data – The data that will be written (can be a string or a Buffer).
Returns: The number of bytes from data which were actually written.
See also
-
io.FIle.prototype.writeLine(data)¶ Same as
io.FIle.prototype.write(), but add a newline (\n) at the end.
-
io.FIle.prototype.close()¶ Close the file.
Functions¶
-
io.open(path, mode[, buffering])¶ Opens the file at the given path in the given mode. Check fopen(3) for the mode details. It returns a
io.File()object.If buffering is specified, it must be
-1(for default buffering),0(for unbuffeered) or1for line buffering). See setvbuf(3).
-
io.fdopen(fd, mode[, path][, buffering])¶ Opens the fiven file descriptor in fd as a
io.File()object. The given mode must be compatible with how the file descriptor was opened. path is purely informational.If buffering is specified, it must be
-1(for default buffering),0(for unbuffeered) or1for line buffering). See setvbuf(3).See also
-
io.readFile(path)¶ Returns the contents of the file at the given path as a Uint8Array.
io.select¶
This object provides access to select(2).
-
select.select(rfds, wfds, xfds, timeout)¶ Wait until any of the given file descriptors are ready for reading, writing or have a pending exceptional condition.
Arguments: - rfds – Array of file descriptors to monitor for reading.
- wfds – Array of file descriptors to monitor for writing.
- xfds – Array of file descriptors to monitor for pending exceptional conditions.
- timeout – Amount of time to wait.
nullmeans unlimited. This function might return early if interrupted by a signal.
Returns: An object containing 3 properties: rfds, wfds and xfds, containing the file descriptors which are ready for each condition respectively.
For more information see select(2).
io.poll¶
This object provides access to poll(2).
-
poll.POLLIN¶
-
poll.POLLOUT¶
-
poll.POLLPRI¶
-
poll.POLLRDHUP¶
-
poll.POLLERR¶
-
poll.POLLHUP¶
-
poll.POLLINVAL¶ Constants to be used in the events or revents fields of a
pollfdobject. Check poll(2) for more information. Note that not all these constants might be available on your platform.
-
poll.poll(pfds, timeout)¶ Examines the given file descriptors to see if some of them are ready for i/o or if certain events have occurred on them.
Arguments: - pfds – An array of
pollfdobjects to be examined. Apollfdobject is any object which has a fd and a events properties. The events property must contain the or-ed events that the user is interested in examining. - timeout – Amount of time to wait.
nullmeans unlimited. This function might return early if interrupted by a signal.
Returns: An array of
pollfdobjects, containing fd, events and revents properties. fd and events match the given ones, and revents indicates the received events.For more information see poll(2).
- pfds – An array of