π File
A File represents an entry to a system file.
info
π¦ Authority: This class can only be spawned on Server.
info
It is not possible to open files from outside the server folder. All path must be relative to the Serverβs executable folder. All files are opened as binary file by default.
Exampleβ
local configuration_file = File("my_awesome_configuration.json")
local configuration_file_json = JSON.parse(configuration_file:Read(configuration_file:Size()))
Constructor Parametersβ
Type | Name | Default | Description |
---|---|---|---|
string | file_path | Path relative to server executable | |
boolean | truncate | false | Whether or not to clear the file upon opening it |
Static Functionsβ
Returns | Name | Description |
---|---|---|
number | Time | Returns when a file was last modified in Unix time |
boolean | CreateDirectory | Creates a Directory (for every folder passed\ |
number | Remove | Deletes a folder or file |
boolean | Exists | Verifies if a entry exists in the file system |
boolean | IsDirectory | Checks if a path is a directory |
boolean | IsRegularFile | Checks if a path is a file |
Time
β
Returns when the file was last modified in Unix time
Returns number
File.Time(path)
Type | Parameter | Description |
---|---|---|
string | path | Path to file |
CreateDirectory
β
Creates a directory (for every folder passed)
Returns boolean if succeeded
File.CreateDirectory(path)
Type | Parameter | Description |
---|---|---|
string | path | Path to folder |
Remove
β
Deletes a folder or a file
Returns number
File.Remove(path)
Type | Parameter | Description |
---|---|---|
string | path | Path to file or folder |
Exists
β
Gets if a file or folder exists
Returns boolean
File.Exists(path)
Type | Parameter | Description |
---|---|---|
string | path | Path to file or folder |
IsDirectory
β
Gets if a path is a directory
Returns boolean
File.IsDirectory(path)
Type | Parameter | Description |
---|---|---|
string | path | Path to folder |
IsRegularFile
β
Gets if a path is a file
Returns boolean
File.IsRegularFile(path)
Type | Parameter | Description |
---|---|---|
string | path | Path to file |
Functionsβ
Returns | Name | Description |
---|---|---|
Close | Closes the file | |
Flush | Flushes content to the file | |
boolean | IsEOF | Checks if the file status is End of File |
boolean | IsBad | Checks if the file status is Bad |
boolean | IsGood | Checks if the file status is Good |
boolean | HasFailed | Checks if the last operation has Failed |
string | Read | Reads characters from the File and returns it. Also moves the file pointer to the latest read position. Pass 0 to read the whole file |
string | ReadAsync | Reads characters from the File asynchronously. |
string | ReadLine | Reads and returns the next file line |
Seek | Sets the file pointer to a specific position | |
number | Size | Returns the size of the file |
Skip | Skips n (amount) positions from the current file pointer position | |
number | Tell | Returns the current file pointer position |
Write | Writes the Data at the current position of the file |
Close
β
Closes the file
my_file:Close()
Flush
β
Flushes content to the file
my_file:Flush()
IsEOF
β
Checks if the file status is End of File
Returns boolean
my_file:IsEOF()
IsBad
β
Checks if the file status is Bad
Returns boolean
my_file:IsBad()
IsGood
β
Checks if the file status is Good
Returns boolean
my_file:IsGood()
HasFailed
β
Checks if the last operation has Failed
Returns boolean
my_file:HasFailed()
Read
β
Reads n (Length) characters from the File and returns it. Also moves the file pointer to the latest read position. Pass 0 to read the whole file
Returns string
my_file:Read(length)
Type | Parameter | Default Value | Description |
---|---|---|---|
number | length | 0 | Length to be read from file |
ReadAsync
β
Reads n (Length) characters from the File asynchronously. Also moves the file pointer to the latest read position. Pass 0 to read the whole file
my_file:ReadAsync(length, function(content)
end)
Type | Parameter | Default Value | Description |
---|---|---|---|
number | length | Length to be read from file | |
function | callback | Callback with the file read |
ReadLine
β
Reads and returns the next file line
Returns string
my_file:ReadLine()
Seek
β
Sets the file pointer to a specific position
my_file:Seek(position)
Type | Parameter | Description |
---|---|---|
number | position | Position to offset the file pointer |
Size
β
Returns the size of the file
Returns number
my_file:Size()
Skip
β
Skips n (amount) positions from the current file pointer position
my_file:Skip(amount)
Type | Parameter | Description |
---|---|---|
number | amount | Amount to offset the file pointer |
Tell
β
Returns the current file pointer position
Returns number
my_file:Tell()
Write
β
Writes the Data at the current position of the file
my_file:Write(data)
Type | Parameter | Description |
---|---|---|
string | data | Writes the data to the file |