FileSystem
Class: FileSystem
A singleton class that provides file system operations.
Static Methods
getInstance
static getInstance(): FileSystem
Gets the singleton instance of FileSystem.
- Returns: FileSystem instance
Methods
ls
ls(targetPath: string, directory?: boolean): Promise<FileInfo[]>
Lists files and directories in the specified path.
- Parameters:
targetPath: The path to listdirectory: Optional flag to filter directories
- Returns:
Promise<FileInfo[]>
exists
exists(p: string): Promise<boolean>
Checks if a file or directory exists.
- Parameters:
p: The path to check
- Returns:
Promise<boolean>
isDirectory
isDirectory(p: string): Promise<boolean>
Checks if the path is a directory.
- Parameters:
p: The path to check
- Returns:
Promise<boolean>
isFile
isFile(p: string): Promise<boolean>
Checks if the path is a file.
- Parameters:
p: The path to check
- Returns:
Promise<boolean>
mkdir
mkdir(p: string, parents?: boolean): Promise<boolean>
Creates a directory.
- Parameters:
p: The directory pathparents: Optional flag to create parent directories
- Returns:
Promise<boolean>
cp
cp(source: string, target: string): Promise<boolean>
Copies a file or directory.
- Parameters:
source: Source pathtarget: Target path
- Returns:
Promise<boolean>
mv
mv(source: string, target: string): Promise<boolean>
Moves a file or directory.
- Parameters:
source: Source pathtarget: Target path
- Returns:
Promise<boolean>
rm
rm(p: string): Promise<boolean>
Removes a file.
- Parameters:
p: The file path
- Returns:
Promise<boolean>
rmdir
rmdir(p: string, recursive?: boolean): Promise<boolean>
Removes a directory.
- Parameters:
p: The directory pathrecursive: Optional flag to remove recursively
- Returns:
Promise<boolean>
ren
ren(source: string, name: string): Promise<boolean>
Renames a file or directory.
- Parameters:
source: Source pathname: New name
- Returns:
Promise<boolean>
cat
cat(p: string): Promise<string>
Reads file content as string.
- Parameters:
p: The file path
- Returns:
Promise<string>
read
read(p: string): Promise<string>
Alias for cat.
- Parameters:
p: The file path
- Returns:
Promise<string>
write
write(p: string, text?: string, mode?: WriteMode): Promise<boolean>
Writes content to a file.
- Parameters:
p: The file pathtext: Optional content to writemode: Optional write mode (truncate/create/append)
- Returns:
Promise<boolean>
touch
touch(p: string): Promise<boolean>
Creates an empty file or updates its timestamp.
- Parameters:
p: The file path
- Returns:
Promise<boolean>
zip
zip(source: string[], target: string): Promise<boolean>
Creates a zip archive.
- Parameters:
source: Array of source pathstarget: Target zip file path
- Returns:
Promise<boolean>
unzip
unzip(source: string, target: string): Promise<boolean>
Extracts a zip archive.
- Parameters:
source: Source zip file pathtarget: Target directory path
- Returns:
Promise<boolean>
tar
tar(source: string[], target: string, mode?: CompressionMode): Promise<boolean>
Creates a tar archive.
- Parameters:
source: Array of source pathstarget: Target tar file pathmode: Optional compression mode
- Returns:
Promise<boolean>
untar
untar(source: string, target: string, mode?: CompressionMode): Promise<boolean>
Extracts a tar archive.
- Parameters:
source: Source tar file pathtarget: Target directory pathmode: Optional compression mode
- Returns:
Promise<boolean>
Enums
WriteMode
enum WriteMode {
TRUNCATE = "truncate",
CREATE = "create",
APPEND = "append"
}
CompressionMode
enum CompressionMode {
NONE = "",
GZIP = "gzip"
}
Types
FileInfo
interface FileInfo {
name: string;
fullname: string;
dirname: string;
mode: number;
size: number;
atimeMs: number;
mtimeMs: number;
ctimeMs: number;
}