Module fs.filedes

Low-level file I/O.

This module groups functions that do file I/O using descriptors.

End-users don’t need to use this module: the fs module provides a higher-level interface to file I/O via fs.open.

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 to fs.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 to fs.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.
generated by LDoc 1.4.3 Last updated 2016-08-23 17:29:40