Skip to content

File System

Provides access to a service's isolated file system.

local fs = require "fs"

Methods

fs.open

fs.open(path: string, mode: "r" | "w" | "a" | "r+" | "w+" | "a+") -> File

Opens the file.

fs.type

fs.type(file: any) -> nil | "file" | "closed file"

Check if file is a file instance. Returns "file" if it is an open file, "closed file" if it is a closed one, or nil if it is not one.

fs.mkdir

fs.mkdir(path: string, all?: boolean)

Creates a directory.

Errors if path points to source.

fs.rename

fs.rename(from: string, to: string)

Renames an entry.

Errors if path points to source.

fs.remove

fs.remove(path: string, all?: boolean)

Removes a file or directory.

if all is set to true and path points to a directory that is not empty, it will remove all files inside it. Be careful!

Errors if path points to source.

fs.metadata

fs.metadata(path: string) -> { kind: "dir" | "file", size?: integer }

Gets basic information about an entry.

Types

File

type File: Stream<string>, BufStream, Sink<string> = <userdata>

Representation of a file.

File:read

File:read(...modes: ReadMode) -> ...string

Reads some bytes from the file.

When no arguments is passed, a random amount of bytes is returned, which is different from files from vanilla Lua and corresponds to Stream<string>:read.

This method extends BufStream:read so that multiple read modes can be passed at the same time, returning multiple strings.

File:write

File:write(...bytes: string) -> File

Writes some bytes from the file.

This method extends Sink<string>:write, allowing multiple bytes to be written once.

File:seek

File:seek(whence: "set" | "cur" | "end", pos: integer) -> integer

File:lines

File:lines(mode: stream.ReadMode) -> iterator<string>

File:flush

File:flush()

File:close

File:close()