fsd (RPC API)#
The RPC calls provided by fsd are the following:
- os.rpc.fs.open(path, mode)#
Open a file descriptor on the given path. The mode can be one of the following:
"r"Open the file for reading.
"w"Open the file for writing. Deletes the destination file if it already existed. Copy on write is used.
In all cases, bytes will be returned; no byte transformation will be performed.
The function returns the following:
If the request has succeeded,
truefollowed by the numerical file descriptor to be used in subsequent calls.If the request has failed,
falsefollowed by an error message.
- Parameters:
path (
string) – Path of the file to open.mode (
string) – Opening mode.
- Returns:
The file context.
- Return type:
number
File descriptor calls#
These calls happen on the file context provided by os.rpc.fs.open().
- os.rpc.fs.file.read(count)#
Read
countbytes from the file descriptor represented by its numerical identifierfd. The function returns the bytes as a Lua string.- Parameters:
count (
number) – Number of requested bytes.- Returns:
Up to
countbytes.- Return type:
string
- os.rpc.fs.file.write(bytes)#
Write the given bytes to the given file descriptor.
- Parameters:
bytes (
string) – The bytes to write.- Returns:
The number of written bytes.
- Return type:
number
- os.rpc.fs.file.sync()#
Synchronize the file’s in-core state with the storage device (what others call “flushing” for write handles).
- os.rpc.fs.file.seek(whence, offset)#
Seek to a position.
- Parameters:
whence (
string) – “set”, “cur” or “end”.offset (
number) – The offset.
- Returns:
The new position.
- Return type:
number