Skip to content

Library: File System

Aviril edited this page Nov 29, 2024 · 7 revisions

━ What's the Objective?

File module simulates file system as may have been observed in other languages (Javascript for example). Custom file manager module was essentially needed for us due to our usecase reasons also since MTA not being capable of supporting relative file paths (Cringe?🤣)

━ How to Import?

Add the below code once in either of the shared .lua script of the resource you want to use within:

--Declare it globally only once
loadstring(exports.assetify_library:import("filesystem"))()

━ APIs

━ assetify.file:exists() (Shared)

@Objective: Verifies whether the specified file exists.
local bool: result = assetify.file:exists(
  string: path
)

━ assetify.file:delete() (Shared)

@Objective: Deletes the specified file.
local bool: result = assetify.file:delete(
  string: path
)

━ assetify.file:read() (Shared)

@Objective: Retrieves specified path's buffer data.
local string: result = assetify.file:read(
  string: path
)

━ assetify.file:write() (Shared)

@Objective: Writes buffer data to a specified path.
local bool: result = assetify.file:write(
  string: path,
  string: data
)

━ assetify.file:parseURL() (Shared)

@Objective: Parses url & returns all possible known datas.
local table: result = assetify.file:parseURL(
  string: path
)

result: {
    pointer = string: pointer, --rootDir (~/url) / localDir (@/url) / false
    url = string: url
    extension = string: extension, --Extension of file. (If detected any)
    file = string: file --Name of file. (If detected any)
    directory = string: directory  --Directory list the file is located within. (If detected any)
}

━ assetify.file:resolveURL() (Shared)

@Objective: Resolves & returns resolved url.
local string: result = assetify.file:resolveURL(
  string: path, --This can be relative path such as "@/dirA/dirB/dirC/.../.../dirD/file.json", "~/dirA/dirB/dirC/.../.../dirD/file.json", "dirB/dirC/.../.../dirD/file.json" etc
  string: chroot --(Optional) If specified resolver will be limited within specified chroot's scope
)

Clone this wiki locally