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, true followed by the numerical file descriptor to be used in subsequent calls.

  • If the request has failed, false followed 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 count bytes from the file descriptor represented by its numerical identifier fd. The function returns the bytes as a Lua string.

Parameters:

count (number) – Number of requested bytes.

Returns:

Up to count bytes.

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