Skip to content

fs

unlink = ( path: string ): void

Deletes a file if it exists.

Parameters

Name Type Description
path string The path to the file to delete.

Returns: {void}


exists

exists = ( path: string ): boolean

Checks if a file or directory exists.

Parameters

Name Type Description
path string The path to the file or directory to check.

Returns: {boolean}trueif the file or directory exists,falseotherwise.


isFile

isFile = ( path: string ): boolean

Checks if a path is a file.

Parameters

Name Type Description
path any the

Returns: true if the path is a file


isDirectory

isDirectory = ( path: string ): boolean

Checks if a path is a directory.

Parameters

Name Type Description
path any the

Returns: true if the path is a directory


mkdir

mkdir = ( dirname: string, mode: number = 0o755, recursive: boolean = true )

mkdir - creates a new directory

Parameters

Name Type Description
dirname any directory name to be created
mode any [0o755] directory mode
recursive any [true] if missing sub dirs should be created.

Returns: ``


rmdir

rmdir = ( dirname: string )

Deletes a directory if it exists.

Parameters

Name Type Description
dirname string The path to the directory to delete.

Returns: {void}


rm

rm = ( fname: string )

Deletes a file if it exists.

Parameters

Name Type Description
fname string The path to the file to delete.

Returns: {void}


readdir

readdir = ( dirname: string ): string[]

Reads the contents of a directory.

Parameters

Name Type Description
dirname string The path to the directory to read.

Returns: {string[]} An array of filenames in the directory.


read

read = ( fname: string ): string

Reads the contents of a file.

Parameters

Name Type Description
fname string The path to the file to read.

Returns: {string} The contents of the file as a string.


abspath

abspath = ( rel_path: string ): string

Resolves a relative path to an absolute path.

Parameters

Name Type Description
rel_path string The relative path to resolve.

Returns: {string} The absolute path.


rename

rename = ( old_path: string, new_path: string ): void

Renames a file or directory.

Parameters

Name Type Description
old_path string The path to the file or directory to rename.
new_path string The new path for the file or directory.

Returns: {void}


move

move = ( old_path: string, new_path: string ): boolean

move ( old_path, new_path ) => void

Moves a file from old_path to new_path.

This function first tries using rename function. If it cannot be used, then the file is copied and removed.

@see rename

Parameters

Name Type Description
old_path: any
new_path: any

Returns: ``


write

write = ( full_path: string, data: string | Buffer ): void

Writes data to a file.

Parameters

Name Type Description
full_path string The path to the file to write to.
data string The data to write to the file.

Returns: {void}


stat

stat = ( full_path: string )

Gets information about a file or directory.

Parameters

Name Type Description
full_path string The path to the file or directory to get information about.

Returns: {fs.Stats} An object containing information about the file or directory.


basename

basename = ( full_path: string )

Gets the base name of a file or directory path.

Parameters

Name Type Description
full_path string The path to the file or directory.

Returns: {string} The base name of the file or directory.


``


@ignore creates a temp file in the full_path given. This function is sync.

Parameters

Name Type Description
path any the
name any the
mode any file

Returns: the full_path of the created file


symlink = ( src: string, dest: string ): void

Creates a symbolic link.

Parameters

Name Type Description
src string The path to the source file or directory.
dest string The path to the destination file or directory.

Returns: {void}


createWriteStream

createWriteStream = ( path: string, options: any )

Creates a write stream to the specified path with the given options.

Parameters

Name Type Description
path any The path to the file.
options any The options for creating the write stream.

Returns: The created write stream.


sanitize

sanitize = ( filename: string )

Takes a filename and returns a sanitized version of it. By default, it replaces all non-alphanumeric characters with underscores and converts to lowercase.

Parameters

Name Type Description
filename string The filename to sanitize.

Returns: {string} The sanitized filename.


fileSize

fileSize = ( path: string ): number

Returns the size of a file in bytes.

Parameters

Name Type Description
path any the

Returns: the size of the file in bytes