Skip to main content
Version: 9.0.0

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.

ParameterTypeDescription
optionsReadFileOptions<J>ReadFile Options.

ReadFileOptions

ParameterTypeDescription
pathstringPath to the file.
asJSONbooleanParse 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.

ParameterTypeDescription
optionsWriteFileOptionsWriteFile Options.

WriteFileOptions

ParameterTypeDescription
pathstringPath to the file.
contentanyContent to write to the file.
asJSONbooleanSerialize content as JSON (optional).
overwritebooleanOverwrite 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.

ParameterTypeDescription
optionsDeleteFileOptionsDeleteFile Options.

DeleteFileOptions

ParameterTypeDescription
pathstringPath 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.

ParameterTypeDescription
optionsCopyFileOptionsCopyFile Options.

CopyFileOptions

ParameterTypeDescription
sourcePathstringPath to the source file.
targetPathstringPath to the target location.
overwritebooleanOverwrite 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.

ParameterTypeDescription
optionsMoveFileOptionsMoveFile Options.

MoveFileOptions

ParameterTypeDescription
sourcePathstringPath to the source file.
targetPathstringPath to the target location.
overwritebooleanOverwrite 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.

ParameterTypeDescription
optionsRenameFileOptionsRenameFile Options.

RenameFileOptions

ParameterTypeDescription
pathstringPath to the file to rename.
newNamestringNew name for the file.
overwritebooleanOverwrite 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.

ParameterTypeDescription
optionsFindFilesOptionsFindFiles Options.

FindFilesOptions

ParameterTypeDescription
pathstringPath to the directory to start the search.
queriesFindFileQuery[]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.

ParameterTypeDescription
optionsGetFileInfoOptionsGetFileInfo Options.

GetFileInfoOptions

ParameterTypeDescription
pathstringPath 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.

ParameterTypeDescription
optionsCheckFileExistsOptionsCheckFileExists Options.

CheckFileExistsOptions

ParameterTypeDescription
pathstringPath 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.

ParameterTypeDescription
optionsCreateDirectoryOptionsCreateDirectory Options.

CreateDirectoryOptions

ParameterTypeDescription
pathstringPath to the new directory to be created.
overwritebooleanOverwrite 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.

ParameterTypeDescription
optionsDeleteDirectoryOptionsDeleteDirectory Options.

DeleteDirectoryOptions

ParameterTypeDescription
pathstringPath 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.

ParameterTypeDescription
optionsRenameDirectoryOptionsRenameDirectory Options.

RenameDirectoryOptions

ParameterTypeDescription
pathstringPath to the directory to be renamed.
newNamestringNew name for the directory.
overwritebooleanOverwrite 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.

ParameterTypeDescription
optionsCopyDirectoryOptionsCopyDirectory Options.

CopyDirectoryOptions

ParameterTypeDescription
sourcePathstringPath to the source directory to be copied.
targetPathstringPath to the target directory for the copy.
overwritebooleanOverwrite 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.

ParameterTypeDescription
optionsMoveDirectoryOptionsMoveDirectory Options.

MoveDirectoryOptions

ParameterTypeDescription
sourcePathstringPath to the source directory to be moved.
targetPathstringPath to the target directory for the move.
overwritebooleanOverwrite 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.

ParameterTypeDescription
optionsGetDirectoryInfoOptionsGetDirectoryInfo Options.

GetDirectoryInfoOptions

ParameterTypeDescription
pathstringPath 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.

ParameterTypeDescription
optionsFindDirectoriesOptions<T>FindDirectories Options.

FindDirectoriesOptions

ParameterTypeDescription
pathstringPath to the directory where the search starts.
queriesFindFileQuery[]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.

ParameterTypeDescription
optionsCheckDirectoryExistsOptionsCheckDirectoryExists Options.

CheckDirectoryExistsOptions

ParameterTypeDescription
pathstringPath 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.

ParameterTypeDescription
fileNamestringName 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.

ParameterTypeDescription
options{ fileName, timeout }Options for waiting for file download.
fileNamestringName of the file to wait for.
timeoutnumberMaximum 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);