Cosmic Docs

Theme
cs.files

File System

Provides a cross platform API to create and manage files. Functions with path params can be absolute or relative to the cwd.

cs.files.read path: string ) Uint8Array

Reads a file as raw bytes. Returns the contents on success or null.

cs.files.readAsync path: string ) Promise

cs.files.readText path: string ) string

Reads a file as a UTF-8 string. Returns the contents on success or null.

cs.files.readTextAsync path: string ) Promise

cs.files.write path: string, buffer: Uint8Array ) boolean

Writes raw bytes to a file. If the file already exists, it's replaced. Returns true on success or false.

cs.files.writeAsync path: string, buffer: Uint8Array ) Promise

cs.files.writeText path: string, str: string ) boolean

Writes UTF-8 text to a file. If the file already exists, it's replaced. Returns true on success or false.

cs.files.writeTextAsync path: string, str: string ) Promise

cs.files.append path: string, buffer: Uint8Array ) boolean

Appends raw bytes to a file. File is created if it doesn't exist. Returns true on success or false.

cs.files.appendAsync path: string, buffer: Uint8Array ) Promise

cs.files.appendText path: string, str: string ) boolean

Appends UTF-8 text to a file. File is created if it doesn't exist. Returns true on success or false.

cs.files.appendTextAsync path: string, str: string ) Promise

cs.files.copy from: string, to: string ) boolean

Copies a file.

cs.files.copyAsync from: string, to: string ) Promise

cs.files.move from: string, to: string ) boolean

Moves a file.

cs.files.moveAsync from: string, to: string ) Promise

cs.files.cwd (  ) string

Returns the absolute path of the current working directory.

cs.files.getPathInfo path: string ) PathInfo

Returns info about a file, folder, or special object at a given path.

cs.files.getPathInfoAsync path: string ) Promise

cs.files.listDir path: string ) []FileEntry

List the files in a directory. This is not recursive.

cs.files.listDirAsync path: string ) Promise

cs.files.ensurePath path: string ) boolean

Ensures that a path exists by creating parent directories as necessary.

cs.files.ensurePathAsync path: string ) Promise

cs.files.pathExists path: string ) boolean

Returns whether something exists at a path.

cs.files.pathExistsAsync path: string ) Promise

cs.files.remove path: string ) boolean

Removes a file.

cs.files.removeAsync path: string ) Promise

cs.files.removeDir path: string, recursive: boolean ) boolean

Removes a directory.

cs.files.removeDirAsync path: string, recursive: boolean ) Promise

cs.files.expandPath path: string ) string

Expands relative pathing such as '..' from the cwd and returns an absolute path. See realPath to resolve symbolic links.

cs.files.realPath path: string ) string

Expands relative pathing from the cwd and resolves symbolic links. Returns the canonicalized absolute path. Path provided must point to a filesystem object.

cs.files.symLink symPath: string, targetPath: string )

Creates a symbolic link (a soft link) at symPath to an existing or nonexisting file at targetPath.

cs.files.PathInfo object
kind: FileKind
atime: number
mtime: number
ctime: number

cs.files.FileEntry object
name: string
kind: string