Module fs.filedes
Low-level file I/O.
This module groups functions that do file I/O using descriptors.
Functions
close(fd) | Closes a file. |
fstat(fd[, ...]) | Stats a file. |
lseek(fd, offset, [whence]) | Seeks in a file. |
open(path, [flags], [mode]) | Opens a file. |
read(fd, count) | Reads from a file. |
write(fd, str) | Writes to a file. |
Functions
- close(fd)
- Closes a file.
- fstat(fd[, ...])
-
Stats a file.
Parameters:
- fd The file descriptor.
- ... Either none, to return a whole fs.StatBuf, or names of fields (rationale explained at fs.stat).
- lseek(fd, offset, [whence])
-
Seeks in a file.
On success returns the new offset (relative to the beginning of the file); on error a triad.
Parameters:
- fd The file descriptor.
- offset The offset (number).
- whence
One of
fs.SEEK_SET
,fs.SEEK_CUR
,fs.SEEK_END
. Defaults tofs.SEEK_SET
.
- open(path, [flags], [mode])
-
Opens a file.
Returns a numeric file descriptor on success, a triad on error.
local fd = require("fs.filedes").open( "/path/to/file", utils.bit32.bor(fs.O_WRONLY, fs.O_EXCL), tonumber("777", 8) )
Parameters:
- path The path
- flags
A bit field. A bitwise “or” of
fs.O_RDONLY
,fs.O_WRONLY
,fs.O_RDWR
, etc. Defaults tofs.O_RDONLY
. - mode When creating a file, the permissions. Defaults to 0666. This will be clipped by the umask.
- read(fd, count)
-
Reads from a file.
On success returns the string read (may be an empty string if no data was available; e.g., on EOF), or a triad on error.
Parameters:
- fd The file descriptor.
- count The number of bytes to read.
- write(fd, str)
-
Writes to a file.
On success returns the number of bytes written. On error: a triad.
Parameters:
- fd The file descriptor.
- str The string to write.