IO
The IO API provides functionality for input/output operations, such as reading, writing, deleting files, and managing directories. Below are the available methods and their usage.
readFile
Description: Reads a file based on the provided options.
Parameter | Type | Description |
---|---|---|
options | ReadFileOptions<J> | ReadFile Options. |
ReadFileOptions
Parameter | Type | Description |
---|---|---|
path | string | Path to the file. |
asJSON | boolean | Parse file content as JSON (optional). |
Basic Usage
const content = await I.readFile({
path: '/path/to/file.txt',
asJSON: true
});
console.log(content);
writeFile
Description: Writes content to a file based on the provided options.
Parameter | Type | Description |
---|---|---|
options | WriteFileOptions | WriteFile Options. |
WriteFileOptions
Parameter | Type | Description |
---|---|---|
path | string | Path to the file. |
content | any | Content to write to the file. |
asJSON | boolean | Serialize content as JSON (optional). |
overwrite | boolean | Overwrite the file if it already exists(optional). |
Basic Usage
const options = {
path: '/path/to/file.txt',
content: 'Hello, World!',
overwrite: true
};
const result = await I.writeFile(options);
console.log(result);
deleteFile
Description: Deletes a file based on the provided options.
Parameter | Type | Description |
---|---|---|
options | DeleteFileOptions | DeleteFile Options. |
DeleteFileOptions
Parameter | Type | Description |
---|---|---|
path | string | Path to the file to delete. |
Basic Usage
const options = {
path: '/path/to/file.txt'
};
await I.deleteFile(options);
copyFile
Description: Copies a file based on the provided options.
Parameter | Type | Description |
---|---|---|
options | CopyFileOptions | CopyFile Options. |
CopyFileOptions
Parameter | Type | Description |
---|---|---|
sourcePath | string | Path to the source file. |
targetPath | string | Path to the target location. |
overwrite | boolean | Overwrite if a file with the same name exists (optional). |
Basic Usage
const options = {
sourcePath: '/path/to/source/file.txt',
targetPath: '/path/to/target/directory',
overwrite: true
};
await I.copyFile(options);
moveFile
Description: Moves a file based on the provided options.
Parameter | Type | Description |
---|---|---|
options | MoveFileOptions | MoveFile Options. |
MoveFileOptions
Parameter | Type | Description |
---|---|---|
sourcePath | string | Path to the source file. |
targetPath | string | Path to the target location. |
overwrite | boolean | Overwrite if a file with the same name exists (optional). |
Basic Usage
const options = {
sourcePath: '/path/to/source/file.txt',
targetPath: '/path/to/target/directory',
overwrite: true
};
await I.moveFile(options);
renameFile
Description: Renames a file based on the provided options.
Parameter | Type | Description |
---|---|---|
options | RenameFileOptions | RenameFile Options. |
RenameFileOptions
Parameter | Type | Description |
---|---|---|
path | string | Path to the file to rename. |
newName | string | New name for the file. |
overwrite | boolean | Overwrite if a file with the new name exists (optional). |
Basic Usage
const options = {
path: '/path/to/file.txt',
newName: 'newName.txt',
overwrite: true
};
await I.renameFile(options);
findFiles
Description: Finds files based on the provided options.
Parameter | Type | Description |
---|---|---|
options | FindFilesOptions | FindFiles Options. |
FindFilesOptions
Parameter | Type | Description |
---|---|---|
path | string | Path to the directory to start the search. |
queries | FindFileQuery[] | Queries to filter the search (optional). |
Basic Usage
const options = {
path: '/path/to/start/search',
queries: [{ type: 'exact', value: 'file.txt' }]
};
const files = await I.findFiles(options);
console.log(files);
getFileInfo
Description: Retrieves information about a file based on the provided options.
Parameter | Type | Description |
---|---|---|
options | GetFileInfoOptions | GetFileInfo Options. |
GetFileInfoOptions
Parameter | Type | Description |
---|---|---|
path | string | Path to the file for which to get info. |
Basic Usage
const options = {
path: '/path/to/file.txt'
};
const fileInfo = await I.getFileInfo(options);
console.log(fileInfo);
checkFileExists
Description: Checks if a file exists based on the provided options.
Parameter | Type | Description |
---|---|---|
options | CheckFileExistsOptions | CheckFileExists Options. |
CheckFileExistsOptions
Parameter | Type | Description |
---|---|---|
path | string | Path to the file to check for existence. |
Basic Usage
const options = {
path: '/path/to/file.txt'
};
const fileExists = await I.checkFileExists(options);
console.log(fileExists);
createDirectory
Description: Creates a new directory based on the provided options.
Parameter | Type | Description |
---|---|---|
options | CreateDirectoryOptions | CreateDirectory Options. |
CreateDirectoryOptions
Parameter | Type | Description |
---|---|---|
path | string | Path to the new directory to be created. |
overwrite | boolean | Overwrite if a directory with the same name exists (optional). |
Basic Usage
const options = {
path: '/path/to/new/directory',
overwrite: true
};
await I.createDirectory(options);
deleteDirectory
Description: Deletes a directory based on the provided options.
Parameter | Type | Description |
---|---|---|
options | DeleteDirectoryOptions | DeleteDirectory Options. |
DeleteDirectoryOptions
Parameter | Type | Description |
---|---|---|
path | string | Path to the directory to be deleted. |
Basic Usage
const options = {
path: '/path/to/directory'
};
await I.deleteDirectory(options);
renameDirectory
Description: Renames a directory based on the provided options.
Parameter | Type | Description |
---|---|---|
options | RenameDirectoryOptions | RenameDirectory Options. |
RenameDirectoryOptions
Parameter | Type | Description |
---|---|---|
path | string | Path to the directory to be renamed. |
newName | string | New name for the directory. |
overwrite | boolean | Overwrite if a directory with the same name exists (optional). |
Basic Usage
const options = {
path: '/path/to/directory',
newName: 'newDirectoryName',
overwrite: true
};
await I.renameDirectory(options);
copyDirectory
Description: Copies a directory based on the provided options.
Parameter | Type | Description |
---|---|---|
options | CopyDirectoryOptions | CopyDirectory Options. |
CopyDirectoryOptions
Parameter | Type | Description |
---|---|---|
sourcePath | string | Path to the source directory to be copied. |
targetPath | string | Path to the target directory for the copy. |
overwrite | boolean | Overwrite if a directory with the same name exists (optional). |
Basic Usage
const options = {
sourcePath: '/path/to/source/directory',
targetPath: '/path/to/target/directory',
overwrite: true
};
await I.copyDirectory(options);
moveDirectory
Description: Moves (renames) a directory based on the provided options.
Parameter | Type | Description |
---|---|---|
options | MoveDirectoryOptions | MoveDirectory Options. |
MoveDirectoryOptions
Parameter | Type | Description |
---|---|---|
sourcePath | string | Path to the source directory to be moved. |
targetPath | string | Path to the target directory for the move. |
overwrite | boolean | Overwrite if a directory with the same name exists (optional). |
Basic Usage
const options = {
sourcePath: '/path/to/source/directory',
targetPath: '/path/to/target/directory',
overwrite: true
};
await I.moveDirectory(options);
getDirectoryInfo
Description: Retrieves information about a directory based on the provided options.
Parameter | Type | Description |
---|---|---|
options | GetDirectoryInfoOptions | GetDirectoryInfo Options. |
GetDirectoryInfoOptions
Parameter | Type | Description |
---|---|---|
path | string | Path to the directory for which to get info. |
Basic Usage
const options = {
path: '/path/to/directory'
};
const directoryInfo = await I.getDirectoryInfo(options);
console.log(directoryInfo);
findDirectories
Description: Finds directories based on the provided options.
Parameter | Type | Description |
---|---|---|
options | FindDirectoriesOptions<T> | FindDirectories Options. |
FindDirectoriesOptions
Parameter | Type | Description |
---|---|---|
path | string | Path to the directory where the search starts. |
queries | FindFileQuery[] | Array of queries to filter directories. |
Basic Usage
const options = {
path: '/path/to/directory',
queries: [
{ type: 'exact', value: 'subdir1' },
{ type: 'contains', value: 'sub' }
]
};
const directories = await I.findDirectories(options);
console.log(directories);
checkDirectoryExists
Description: Checks if a directory exists based on the provided options.
Parameter | Type | Description |
---|---|---|
options | CheckDirectoryExistsOptions | CheckDirectoryExists Options. |
CheckDirectoryExistsOptions
Parameter | Type | Description |
---|---|---|
path | string | Path to the directory to be checked. |
Basic Usage
const options = {
path: '/path/to/directory'
};
const directoryExists = await I.checkDirectoryExists(options);
console.log(directoryExists);
setNameOfFileToBeDownloaded
Description: Sets the name of the file to be downloaded. This is typically used in web applications for specifying the name of the file when it is downloaded.
Parameter | Type | Description |
---|---|---|
fileName | string | Name of the file to be set for download. |
Basic Usage
const fileName = 'example.txt';
await I.setNameOfFileToBeDownloaded(fileName);
waitForFileToBeDownloaded
Description: Waits for a file to be downloaded within a specified timeout.
Parameter | Type | Description |
---|---|---|
options | { fileName, timeout } | Options for waiting for file download. |
fileName | string | Name of the file to wait for. |
timeout | number | Maximum time (in milliseconds) to wait. |
Basic Usage
const options = {
fileName: 'example.txt',
timeout: 5000 // 5 seconds
};
const result = await I.waitForFileToBeDownloaded(options);
console.log(result);