#
fs
File system access with restrictions & canonical resolution.
This one allows the use of "..", without breaching the workspace.
#
Functions
fs.separator: string
- The separator character responsible for the current filesystem
fs.read(path: string, async?: function): string?
- Reads a file from a given path
- Runs in async if a function is provided
fs.write(path: string, data: string | buffer, async?: function | boolean)
- Writes to a file provided by the path
- Runs in async if passing a function or boolean
- Function callback acts as trigger from completion
fs.append(path: string, data: string | buffer, async?: function | boolean)
- Appends data onto the specified file
- Runs in async if passing a function or boolean
- Function callback acts as trigger from completion
fs.isfile(path: string): boolean
- Checks if a filesystem object is a file
fs.isfolder(path: string): boolean
- Checks if a filesystem object is a folder
fs.readable(path: string): boolean
- Checks if a filesystem object is readable
fs.writeable(path: string): boolean
- Checks if a filesystem object is writeable
fs.scan(path: string): string[]
- Lists files in the specified path
fs.mkdir(path: string)
- Creates a folder in the specified path
- This is recursive, allowing it to generate multiple folders
fs.rmdir(path: string)
- Deletes a folder from the specified path
fs.rmfile(path: string)
- Deletes a file from the specified path
fs.rm(path: string)
- Deletes any file or folder from the specified path
fs.mv(from: string, to: string): boolean
- Moves any file or folder to a new location
- This will overwrite files
fs.cp(from: string, to: string): boolean
- Copies any file or folder to a new location
- This will overwrite files
fs.forward(path: string): string
- Changes all "\" separators to "/"
fs.backward(path: string): string
- Changes all "/" separators to "\"
fs.join(a: string, b: string): string
- Joins two paths together
fs.extname(path: string, replace?: string): string
- Gets the extension name of a path
- If provided a replacement, will return the replaced path's extension
fs.filename(path: string, replace?: string): string
- Gets the file name of a path
- If provided a replacement, will return the replaced path's file
fs.dirname(path: string, replace?: string): string
- Gets the directory name of a path
- If provided a replacement, will return the replaced path's directory
fs.sanitize(path: string): string
- Removes any oddities in the path, replacing them with "_" instead.
fs.canonical(path: string): string
- Resolves a path to its absolute form.
- This converts special FS directives such as ".." to absolute path.
- Useful for many different situations, like isolation.
fs.within(root: string, path: string): boolean
- Checks if a path is within a root path.
- This works great with functions like fs.canonical to determine isolation.