.. _stdlib_io: io === The I/O module provides various tools for working with files and the filesystem. .. _stdlib_io_Dirent: Dirent ------ Represents a directory entry in the filesystem. construct new(name, type) +++++++++++++++++++++++++ Constructs a new ``Dirent`` with a name and a type. The format of the type is implementation defined but may be copied from another ``Dirent`` if appropriate. name ++++ Returns the name of the directory entry. type ++++ Returns the type of the directory entry. The format of this type is implementation defined. isFifo ++++++ True if this directory entry is a FIFO. isDir +++++ True if this directory entry is a (sub)directory. isChr +++++ True if this directory entry is a character special device. isBlk +++++ True if this directory entry is a block special device. isFile ++++++ True if this directory entry is a regular file. isLink ++++++ True if this directory entry is a symbolic link. isSock ++++++ True if this directory entry is a Unix socket. .. _stdlib_io_File: File ---- An open file descriptor. Open files will eventually be closed by the garbage collector, but to prevent file decsriptor leaks the user should call ``close()`` themselves once the file is no longer needed. Files implement :ref:`context.Context ` to automatically close files. construct fdopen(fd) ++++++++++++++++++++ Creates a ``File`` from an arbitrary file descriptor. static open(path) +++++++++++++++++ Opens a file in read-only mode. static open(path, flags) ++++++++++++++++++++++++ Opens a file with the given :ref:`FileFlags `. static create(path) +++++++++++++++++++ Creates a new file with the default mode, in write-only, truncate mode. static create(path, flags) ++++++++++++++++++++++++++ Create a new file with the default mode and the given :ref:`FileFlags `. static create(path, flags, mode) ++++++++++++++++++++++++++++++++ Create a new file with the given mode and the given :ref:`FileFlags `. read() ++++++ Read the entire contents of the File, returning a byte array. read(count) +++++++++++ Read up to "count" bytes from the File, returning a byte array. The length of the byte array may be less than the amount requested if there was not enough data left. An end of file condition is indicated when this function returns an empty array. write(data) +++++++++++ Write data to a File. Returns the number of bytes written (which is always the complete length of the buffer). close() +++++++ Closes this file. fstat() +++++++ Returns the :ref:`Stat ` for this file seek(offset, whence) ++++++++++++++++++++ Seeks this file to a new offset, relative to a :ref:`Whence `, and returns the new offset relative to the start of the file. tell() ++++++ Returns the current offset in this file. .. _stdlib_io_FileFlag: FileFlag -------- FileFlag provides constants that affect the behavior of opened :ref:`Files `. static readOnly +++++++++++++++ Request read-only usage. static writeOnly ++++++++++++++++ Request write-only usage. static readWrite ++++++++++++++++ Request read/write usage. static exclusive ++++++++++++++++ Request exclusive usage, intended for use with ``File.create`` et al. If the requested file already exists, the Fiber is aborted with an error. static truncate +++++++++++++++ Truncate the opened file. static append +++++++++++++ Append to the file. static sync +++++++++++ Request synchronous I/O. FS -- The FS class provides high-level filesystem operations. static exists(path) +++++++++++++++++++ Returns true if the given path exists. static list(path) +++++++++++++++++ Returns a sorted list of the :ref:`Dirents ` at a given path. static stat(path) +++++++++++++++++ Returns a :ref:`Stat ` for the given path. .. _stdlib_io_Stat: Stat ---- A Stat object describes an inode in the filesystem. mode ++++ Returns the mode bits for this stat. uid +++ Returns the user ID that owns this inode. gid +++ Returns the group ID that owns this inode. size ++++ Returns the size, in bytes, of the file this stat describes. inode +++++ Returns the inode number this stat describes. isFifo ++++++ True if this stat describes a FIFO. isDir +++++ True if this stat describes a (sub)directory. isChr +++++ True if this stat describes a character special device. isBlk +++++ True if this stat describes a block special device. isFile ++++++ True if this stat describes a regular file. isLink ++++++ True if this stat describes a symbolic link. isSock ++++++ True if this stat describes a Unix socket. Stdin, Stdout, Stderr --------------------- :ref:`Files ` respectively representing the current process's standard input, output, and error. .. _stdlib_io_Whence: Whence ------ Whence provides constants which control the behavior of ``File.seek``. static set ++++++++++ Seek relative to the start of the file. static cur ++++++++++ Seek relative to the current file offset. static end ++++++++++ Seek relative to the end of the file.