Skip to content
On this page

@bridge/fs

Module that allows extensions to interact with the user's file system.

Functions

copyFile

copyFile(originPath, destPath): Promise<FileSystemFileHandle>

Copy a file.

Parameters

NameType
originPathstring
destPathstring

Returns

Promise<FileSystemFileHandle>


copyFileHandle

copyFileHandle(originHandle, destHandle): Promise<FileSystemFileHandle>

Copy a file handle.

Parameters

NameType
originHandleFileSystemFileHandle
destHandleFileSystemFileHandle

Returns

Promise<FileSystemFileHandle>


copyFolder

copyFolder(originPath, destPath): Promise<void>

Copy a folder by their paths.

Parameters

NameType
originPathstring
destPathstring

Returns

Promise<void>


copyFolderByHandle

copyFolderByHandle(originHandle, destHandle): Promise<void>

Copy a folder by its FileSystemDirectoryHandle.

Parameters

NameType
originHandleFileSystemDirectoryHandle
destHandleFileSystemDirectoryHandle

Returns

Promise<void>


directoryExists

directoryExists(path): Promise<boolean>

Return whether a directory exists or not.

Parameters

NameType
pathstring

Returns

Promise<boolean>


fileExists

fileExists(path): Promise<boolean>

Return whether a file exists or not.

Parameters

NameType
pathstring

Returns

Promise<boolean>


getDirectoryHandle

getDirectoryHandle(path, __namedParameters): Promise<FileSystemDirectoryHandle>

The getDirectoryHandle() method returns a FileSystemDirectoryHandle for a subdirectory with the specified name within the directory handle on which the method is called.

Parameters

NameTypeDescription
pathstringA USVString representing the FileSystemHandle.name of the subdirectory you wish to retrieve.
__namedParametersPartial<IGetHandleConfig>-

Returns

Promise<FileSystemDirectoryHandle>


getFileHandle

getFileHandle(path, create): Promise<FileSystemFileHandle>

Parameters

NameType
pathstring
createboolean

Returns

Promise<FileSystemFileHandle>


loadFileHandleAsDataUrl

loadFileHandleAsDataUrl(fileHandle): Promise<string>

Read a file by its FileHandle as a URL.

Parameters

NameType
fileHandleFileSystemFileHandle

Returns

Promise<string>


mkdir

mkdir(path, __namedParameters): Promise<void>

Parameters

NameType
pathstring
__namedParametersPartial<IMkdirConfig>

Returns

Promise<void>


readFile

readFile(path): Promise<File>

Read a file and return it.

Parameters

NameType
pathstring

Returns

Promise<File>


readFilesFromDir

readFilesFromDir(path, dirHandle): Promise<{ kind: string ; name: string ; path: string }[]>

Read the contents of a directory and returns the files.

Parameters

NameType
pathstring
dirHandleFileSystemDirectoryHandle | Promise<FileSystemDirectoryHandle>

Returns

Promise<{ kind: string ; name: string ; path: string }[]>


readJSON

readJSON(path): Promise<FileSystemFileHandle>

Read a JSON file at a given path and return the file handle.

Parameters

NameType
pathstring

Returns

Promise<FileSystemFileHandle>


readdir

readdir(path, config): Promise<FileSystemHandle[]>

Read the contents of a given directory.

Parameters

NameType
pathstring
configObject
config.withFileTypestrue

Returns

Promise<FileSystemHandle[]>

readdir(path, config?): Promise<string[]>

Parameters

NameType
pathstring
config?Object
config.withFileTypes?false

Returns

Promise<string[]>

readdir(path, __namedParameters): Promise<FileSystemHandle[]>

Parameters

NameType
pathstring
__namedParametersObject
__namedParameters.withFileTypes?boolean

Returns

Promise<FileSystemHandle[]>


setup

setup(baseDirectory): void

Parameters

NameType
baseDirectoryFileSystemDirectoryHandle

Returns

void


unlink(path): Promise<void>

Unlink a directory from the fileSystem, deleting it.

Parameters

NameType
pathstring

Returns

Promise<void>


write

write(fileHandle, data): Promise<FileSystemFileHandle>

Write to a file from a FileSystemDirectoryHandle.

Parameters

NameType
fileHandleFileSystemFileHandle
dataFileSystemWriteChunkType

Returns

Promise<FileSystemFileHandle>


writeFile

writeFile(path, data): Promise<FileSystemFileHandle>

Write to a file at the specified path.

Parameters

NameType
pathstring
dataFileSystemWriteChunkType

Returns

Promise<FileSystemFileHandle>


writeJSON

writeJSON(path, data, beautify): Promise<FileSystemFileHandle>

Write a javascript object as JSON to a file.

Parameters

NameType
pathstring
dataany
beautifyboolean

Returns

Promise<FileSystemFileHandle>

Released under the GPL-3.0 License.