io
The I/O module provides various tools for working with files and the filesystem.
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.
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 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 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 FileFlags.
static create(path, flags, mode)
Create a new file with the given mode and the given 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 Stat for this file
seek(offset, whence)
Seeks this file to a new offset, relative to a Whence, and returns the new offset relative to the start of the file.
tell()
Returns the current offset in this file.
FileFlag
FileFlag provides constants that affect the behavior of opened 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 Dirents at a given path.
static stat(path)
Returns a Stat for the given path.
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
Files respectively representing the current process’s standard input, output, and error.
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.