std::fs
Structs
struct Status {}
Status information.
Methods:
static fn Of(path: str)!: &Status
Returns a Status describing the path.
Returns nil reference if error occurs.
Possible errors: Denied
IO
Loop
LongPath
NotExist
NotDir
Overflow
fn IsDir(self): bool
Reports path is directory or not.
fn IsReg(self): bool
Reports path is regular file or not.
fn Size(): uint
Total size in bytes of regular file or symbolic link.
struct DirEntry {
Name: str
Stat: &Status
}
Directory entry.
struct File
The file stream handle.
It works like a wrapper when it comes to console handle like stdin, stdout or stderr. Read and write functions are supported for console handlers. The rest of the functions are not supported and not checked, it is undefined behavior.
There may be system call differences and performance differences for console handlers depending on the operating system. For example, Windows has an overhead for UTF-16 processing.
Methods:
static fn New(handle: uintptr): &File
Returns new &File
by handle. If hadle <= 0, returns nil reference.
static fn Open(path: str, flag: OFlag, mode: int)!: &File
Opens file stream with named file, specified flag (OFlag.Rdwr, OFlag.Trunc etc.) and perm. If named file does not exist and OFlag.Creat flag is passed, will created with mode (before umask). If successful, returns File reference with handle to file stream and the reference can used for I/O operations.
Possible errors: Denied
Exist
Signal
SyncIO
IO
IsDir
Loop
PerProcessLimit
LongPath
SystemWideLimit
NotExist
UnableStream
NoSpace
NotDir
Device
Overflow
ReadOnly
Retry
Busy
static fn Remove(path: str)!
Removes named file.
Possible errors: Denined
Busy
LongPath
NotExist
InsufficientMemory
NotDir
static fn Read(path: str)!: []byte
Reads bytes of file. First, learns byte-size of file. Then reads bytes and returns buffer.
Possible errors: Denied
Exist
Signal
SyncIO
IO
IsDir
Loop
PerProcessLimit
LongPath
SystemWideLimit
NotExist
UnableStream
NoSpace
NotDir
Device
Overflow
ReadOnly
Retry
Busy
Device
Seek
InsufficientMemory
Buffer
static fn Write(path: str, data: []byte, perm: int)!
Writes data to the named file, creating it if necessary. If the file does not exist, creates it with permissions perm (before umask); otherwise truncates it before writing, without changing permissions. Since requires multiple system calls to complete, a failure mid-operation can leave the file in a partially written state.
static fn WriteStr(path: str, &data: str, perm: int)!
Same as [File.Write
], designed for strings.
static fn Create(path: str)!: &File
Creates or truncates the named file. If the file already exists, it is truncated. If the file does not exist, it is created with mode 0666 (before umask). If successful, methods on the returned File can be used for I/O; the associated file descriptor has mode OFlag.Rdwr.
fn Seek(mut self, offset: int, origin: Seek)!: int
Sets offset to next Read/Write operation and returns the new offset. whence: 0 (Seek.Set) means, relative to the origin of the file, 1 (Seek.Cur) means relative to the current offset, and 2 (Seek.End) means relative to end.
Possible errors: InvalidDescriptor
SyncIO
Overflow
Seek
fn Read(mut self, mut buff: []byte)!: (n: int)
Read bytes to buffer from handle and returns readed byte count. The number of bytes readed can never exceed the length of the buff. If the buff is larger than the number of bytes that can be read, the buffer will not cause an overflow. Offset will be shifted by the number of bytes read.
Possible errors: Retry
InvalidDescriptor
Signal
SyncIO
IO
IsDir
Overflow
Buffer
InsufficientMemory
Device
Seek
fn Write(mut self, buff: []byte)!: (n: int)
Writes bytes to handle and returns writed byte count. The number of bytes written can never exceed the length of the buff.
Possible errors: Retry
InvalidDescriptor
Big
Signal
IO
NoSpace
Pipe
Range
SyncIO
Seek
Device
Buffer
fn WriteStr(mut self, &data: str)!: (n: int)
Same as [Write
], designed for strings.
fn Close(mut self)!
Closes file handle.
Possible errors: InvalidDescriptor
Signal
IO
struct Directory
Directory.
Methods:
static fn Read(path: str)!: []&DirEntry
Reads the named directory and returs all its directory entries can read.
Possible errors: Denied
InvalidDescriptor
PerProcessLimit
SystemWideLimit
NotExist
InsufficientMemory
NotDir
static fn Create(path: str)!
Creates directory.
Possible errors: Denied
Exist
ReadOnly
NoSpace
static fn Remove(path: str)!
Removes empty directory.
Possible errors: Denied
NotExist
NotEmpty
SyncIO
IO
Loop
NotDir
Enums
enum FsError
Fields:
Denied
: Search permission is denied for a component of the path prefixIO
: Input/Output error, an error occurred while reading from the file systemLoop
: A loop exists in symbolic links encountered during resolution of the path argumentLongPath
: The length of the path argument exceeds maxium path length or a pathname component is longer than maximum name lengthNotExist
: A component of path does not name an existing file or path is an empty stringNotDir
: A component of the path prefix is not a directoryOverflow
: The file size in bytes or the number of blocks allocated to the file or the file serial number cannot be represented correctly in the structure pointed to by bufInvalidDescriptor
: fd is not a valid file descriptor opened for reading.PerProcessLimit
: The per-process limit on the number of open file descriptors has been reached.SystemWideLimit
: The system-wide limit on the total number of open files has been reached.InsufficientMemory
: Insufficient memory to complete the operation.Exist
: A component of path does name an existing fileSignal
: A signal was caught duringSyncIO
: The implementation does not support synchronized I/O for this fileIsDir
: The named file is a directory and flag includes O_WRONLY or O_RDWRUnableStream
: The path argument names a STREAMS-based file and the system is unable to allocate a STREAMNoSpace
: There is no space on the driveDevice
: Device did not respondReadOnly
: Read-only filesystemRetry
: Resource temporarily unavailableBusy
: File is busyBig
: File too largePipe
: Broken pipeRange
: Input is outside the rangeNoDest
: No such device or addressBuffer
: No buffer space availableBadMessage
: Not a data messageNotEmpty
: Not empty
enum Seek: int
Seek whence values.
Fields:
Set
: Seek relative to the origin of the fileCur
: Seek relative to the current offsetEnd
: Seek relative to the end
enum OFlag: int
Flags to open wrapping those of the underlying system.
Not all flags may be implemented on a given system.
Exactly one of Rdonly, Wronly, or Rdwr must be specified.
Fields:
Rdonly
: Open the file read-onlyWronly
: Open the file write-onlyRdwr
: Open the file read-writeAppend
: Append data to the file when writingCreate
: Create a new file if none existsExcl
: Used with OFlag.Create, file must not existSync
: Open for synchronous I/OTrunc
: Truncate regular writable file when opened