Access the file system.
This package is also accessible with window.__TAURI__.fs
when tauri.conf.json > build > withGlobalTauri
is set to true.
The APIs must be allowlisted on tauri.conf.json
:
{
"tauri": {
"allowlist": {
"fs": {
"all": true, // enable all FS APIs
"readTextFile": true,
"readBinaryFile": true,
"writeFile": true,
"writeBinaryFile": true,
"readDir": true,
"copyFile": true,
"createDir": true,
"removeDir": true,
"removeFile": true,
"renameFile": true
}
}
}
}
It is recommended to allowlist only the APIs you use for optimal bundle size and security.
#
Enumerations#
Interfaces#
References#
DirRenames and exports: BaseDirectory
#
Functions#
copyFile▸ copyFile(source
, destination
, options?
): Promise
<void
>
Copys a file to a destination.
#
ParametersName | Type | Description |
---|---|---|
source | string | A path of the file to copy. |
destination | string | A path for the destination file. |
options | FsOptions | Configuration object. |
#
ReturnsPromise
<void
>
A promise indicating the success or failure of the operation.
#
Defined in#
createDir▸ createDir(dir
, options?
): Promise
<void
>
Creates a directory.
If one of the path's parent components doesn't exist
and the recursive
option isn't set to true, the promise will be rejected.
#
ParametersName | Type | Description |
---|---|---|
dir | string | Path to the directory to create. |
options | FsDirOptions | Configuration object. |
#
ReturnsPromise
<void
>
A promise indicating the success or failure of the operation.
#
Defined in#
readBinaryFile▸ readBinaryFile(filePath
, options?
): Promise
<number
[]>
Reads a file as byte array.
#
ParametersName | Type | Description |
---|---|---|
filePath | string | Path to the file. |
options | FsOptions | Configuration object. |
#
ReturnsPromise
<number
[]>
A promise resolving to the file bytes array.
#
Defined in#
readDir▸ readDir(dir
, options?
): Promise
<FileEntry
[]>
List directory files.
#
ParametersName | Type | Description |
---|---|---|
dir | string | Path to the directory to read. |
options | FsDirOptions | Configuration object. |
#
ReturnsPromise
<FileEntry
[]>
A promise resolving to the directory entries.
#
Defined in#
readTextFile▸ readTextFile(filePath
, options?
): Promise
<string
>
Reads a file as UTF-8 encoded string.
#
ParametersName | Type | Description |
---|---|---|
filePath | string | Path to the file. |
options | FsOptions | Configuration object. |
#
ReturnsPromise
<string
>
A promise resolving to the file content as a UTF-8 encoded string.
#
Defined in#
removeDir▸ removeDir(dir
, options?
): Promise
<void
>
Removes a directory.
If the directory is not empty and the recursive
option isn't set to true, the promise will be rejected.
#
ParametersName | Type | Description |
---|---|---|
dir | string | Path to the directory to remove. |
options | FsDirOptions | Configuration object. |
#
ReturnsPromise
<void
>
A promise indicating the success or failure of the operation.
#
Defined in#
removeFile▸ removeFile(file
, options?
): Promise
<void
>
Removes a file.
#
ParametersName | Type | Description |
---|---|---|
file | string | Path to the file to remove. |
options | FsOptions | Configuration object. |
#
ReturnsPromise
<void
>
A promise indicating the success or failure of the operation.
#
Defined in#
renameFile▸ renameFile(oldPath
, newPath
, options?
): Promise
<void
>
Renames a file.
#
ParametersName | Type | Description |
---|---|---|
oldPath | string | A path of the file to rename. |
newPath | string | A path of the new file name. |
options | FsOptions | Configuration object. |
#
ReturnsPromise
<void
>
A promise indicating the success or failure of the operation.
#
Defined in#
writeBinaryFile▸ writeBinaryFile(file
, options?
): Promise
<void
>
Writes a binary file.
#
ParametersName | Type | Description |
---|---|---|
file | FsBinaryFileOption | Write configuration object. |
options | FsOptions | Configuration object. |
#
ReturnsPromise
<void
>
A promise indicating the success or failure of the operation.
#
Defined in#
writeFile▸ writeFile(file
, options?
): Promise
<void
>
Writes a text file.
#
ParametersName | Type | Description |
---|---|---|
file | FsTextFileOption | File configuration object. |
options | FsOptions | Configuration object. |
#
ReturnsPromise
<void
>
A promise indicating the success or failure of the operation.