Browser FS API reference
Exports of @anymux/browser-fs. Back to the module
Classes
BrowserFileSystemImplementation
classclass BrowserFileSystemImplementation
constants
propertyconstants: FSConstants
constructor
constructorconstructor(options?: { encoding?: string; }): BrowserFileSystemImplementationgetInfo
methodGet serializable information about this file system instance
getInfo(): BrowserFsInfo | null
setInfo
methodSet serializable information for this file system instance
setInfo(info: BrowserFsInfo): void
initialize
methodInitialize the file system by requesting a directory from the user
initialize(options?: { id?: string; startIn?: FileSystemHandle | "desktop" | "documents" | "downloads" | "music" | "pictures" | "videos"; mode?: "read" | "readwrite"; }): Promise<void>initializeWithHandle
methodInitialize file system with an existing directory handle
initializeWithHandle(handle: FileSystemDirectoryHandle, fsInfo: BrowserFsInfo): Promise<void>
readFile
methodreadFile(path: string, options?: { encoding?: BufferEncoding; flag?: string; } | BufferEncoding): Promise<Buffer | string>writeFile
methodwriteFile(path: string, data: Buffer | string | Uint8Array, options?: { encoding?: BufferEncoding; mode?: number; flag?: string; }): Promise<void>mkdir
methodmkdir(path: string, options?: { recursive?: boolean; mode?: number; }): Promise<string | undefined>readdir
methodreaddir(path: string, options?: { encoding?: BufferEncoding; withFileTypes?: false; recursive?: boolean; }): Promise<string[]>readdir
methodreaddir(path: string, options: { encoding?: BufferEncoding; withFileTypes: true; recursive?: boolean; }): Promise<Dirent[]>readdir
methodreaddir(path: string, options?: { encoding?: BufferEncoding; withFileTypes?: boolean; recursive?: boolean; }): Promise<string[] | Dirent[]>exists
methodexists(path: string): Promise<boolean>
stat
methodstat(path: string, options?: { bigint?: false; }): Promise<Stats>stat
methodstat(path: string, options: { bigint: true; }): Promise<BigIntStats>stat
methodstat(path: string, options?: { bigint?: boolean; }): Promise<Stats | BigIntStats>unlink
methodunlink(path: string): Promise<void>
rmdir
methodrmdir(path: string, options?: { recursive?: boolean; }): Promise<void>init
methodinit(options?: { encoding?: string; handle?: FileSystemDirectoryHandle; id?: string; name?: string; rootPath?: string; }): Promise<void>appendFile
methodappendFile(path: string, data: Buffer | string | Uint8Array, options?: { encoding?: BufferEncoding; mode?: number; flag?: string; }): Promise<void>copyFile
methodcopyFile(src: string, dest: string, mode?: number): Promise<void>
lstat
methodlstat(path: string, options?: { bigint?: false; }): Promise<Stats>lstat
methodlstat(path: string, options: { bigint: true; }): Promise<BigIntStats>lstat
methodlstat(path: string, options?: { bigint?: boolean; }): Promise<Stats | BigIntStats>rename
methodrename(oldPath: string, newPath: string): Promise<void>
access
methodaccess(path: string, mode?: number): Promise<void>
rm
methodrm(path: string, options?: { force?: boolean; maxRetries?: number; recursive?: boolean; retryDelay?: number; }): Promise<void>cp
methodcp(src: string, dest: string, options?: { dereference?: boolean; errorOnExist?: boolean; filter?: (src: string, dest: string) => boolean | Promise<boolean>; force?: boolean; mode?: number; preserveTimestamps?: boolean; recursive?: boolean; verbatimSymlinks?: boolean; }): Promise<void>mkdtemp
methodmkdtemp(prefix: string, options?: { encoding?: BufferEncoding; }): Promise<string>opendir
methodopendir(path: string, options?: { encoding?: BufferEncoding; bufferSize?: number; recursive?: boolean; }): Promise<IDir>open
methodopen(path: string, flags?: string | number, mode?: number): Promise<IFileHandle>
realpath
methodrealpath(path: string, options?: { encoding?: BufferEncoding; }): Promise<string>statfs
methodstatfs(path: string, options?: { bigint?: false; }): Promise<StatFs>statfs
methodstatfs(path: string, options: { bigint: true; }): Promise<BigIntStatFs>statfs
methodstatfs(path: string, options?: { bigint?: boolean; }): Promise<StatFs | BigIntStatFs>lutimes
methodlutimes(path: string, atime: string | number | Date, mtime: string | number | Date): Promise<void>
lchown
methodlchown(path: string, uid: number, gid: number): Promise<void>
lchmod
methodlchmod(path: string, mode: string | number): Promise<void>
truncate
methodtruncate(path: string, len?: number): Promise<void>
utimes
methodutimes(path: string, atime: string | number | Date, mtime: string | number | Date): Promise<void>
chmod
methodchmod(path: string, mode: string | number): Promise<void>
chown
methodchown(path: string, uid: number, gid: number): Promise<void>
readlink
methodreadlink(path: string, options?: { encoding?: BufferEncoding; }): Promise<string>symlink
methodsymlink(target: string, path: string, type?: "dir" | "file" | "junction"): Promise<void>
link
methodlink(existingPath: string, newPath: string): Promise<void>
isImplemented
methodisImplemented(feature: string): boolean
createReadStream
methodcreateReadStream(path: string, options?: { encoding?: BufferEncoding; start?: number; end?: number; }): ReadStreamcreateWriteStream
methodcreateWriteStream(path: string, options?: { encoding?: BufferEncoding; flags?: string; mode?: number; }): WriteStreamwatch
methodwatch(path: string, options?: { encoding?: BufferEncoding; persistent?: boolean; recursive?: boolean; }): FSWatcherBrowserFileSystemFactory
classFactory for creating BrowserFileSystemImplementation instances This factory provides methods to create file systems either by showing a directory picker to the user or by reusing a previously saved handle.
class BrowserFileSystemFactory
getInstance
methodGet the singleton instance of the factory
getInstance(): BrowserFileSystemFactory
debugDumpDatabase
methodDebug method to dump database contents for diagnostics
debugDumpDatabase(): Promise<void>
getAllHandleInfos
methodGet all stored handle info objects
getAllHandleInfos(): Promise<BrowserFsHandleInfo[]>
updateLastAccessed
methodUpdate the last accessed timestamp for a handle
updateLastAccessed(id: string): Promise<void>
saveHandleWithId
methodSave a file system with a specified ID
saveHandleWithId(id: string, name: string, fs: BrowserFileSystemImplementation): Promise<BrowserFsHandleInfo>
removeHandle
methodRemove a handle from storage
removeHandle(id: string): Promise<void>
createFromPicker
methodCreate a browser file system by showing a directory picker to the user
createFromPicker(options?: { encoding?: string; }, pickerOptions?: { id?: string; name?: string; startIn?: FileSystemHandle | "desktop" | "documents" | "downloads" | "music" | "pictures" | "videos"; mode?: "read" | "readwrite"; }): Promise<[BrowserFileSystemImplementation, BrowserFsHandleInfo]>createFromHandleInfo
methodCreate a browser file system from a previously saved handle
createFromHandleInfo(id: string, options?: { encoding?: string; }): Promise<BrowserFileSystemImplementation | null>HandleStore
classStorage for file system handles to avoid requesting permissions repeatedly
class HandleStore
setRootHandle
methodsetRootHandle(handle: FileSystemDirectoryHandle): void
getRootHandle
methodgetRootHandle(): FileSystemDirectoryHandle | null
getHandle
methodgetHandle(path: string): FileSystemHandle | undefined
setHandle
methodsetHandle(path: string, handle: FileSystemHandle): void
removeHandle
methodremoveHandle(path: string): void
clear
methodclear(): void
FileSystemAccessAPI
classclass FileSystemAccessAPI
constants
propertyconstants: FSConstants
constructor
constructorconstructor(options?: { encoding?: string; }): BrowserFileSystemImplementationgetInfo
methodGet serializable information about this file system instance
getInfo(): BrowserFsInfo | null
setInfo
methodSet serializable information for this file system instance
setInfo(info: BrowserFsInfo): void
initialize
methodInitialize the file system by requesting a directory from the user
initialize(options?: { id?: string; startIn?: FileSystemHandle | "desktop" | "documents" | "downloads" | "music" | "pictures" | "videos"; mode?: "read" | "readwrite"; }): Promise<void>initializeWithHandle
methodInitialize file system with an existing directory handle
initializeWithHandle(handle: FileSystemDirectoryHandle, fsInfo: BrowserFsInfo): Promise<void>
readFile
methodreadFile(path: string, options?: { encoding?: BufferEncoding; flag?: string; } | BufferEncoding): Promise<Buffer | string>writeFile
methodwriteFile(path: string, data: Buffer | string | Uint8Array, options?: { encoding?: BufferEncoding; mode?: number; flag?: string; }): Promise<void>mkdir
methodmkdir(path: string, options?: { recursive?: boolean; mode?: number; }): Promise<string | undefined>readdir
methodreaddir(path: string, options?: { encoding?: BufferEncoding; withFileTypes?: false; recursive?: boolean; }): Promise<string[]>readdir
methodreaddir(path: string, options: { encoding?: BufferEncoding; withFileTypes: true; recursive?: boolean; }): Promise<Dirent[]>readdir
methodreaddir(path: string, options?: { encoding?: BufferEncoding; withFileTypes?: boolean; recursive?: boolean; }): Promise<string[] | Dirent[]>exists
methodexists(path: string): Promise<boolean>
stat
methodstat(path: string, options?: { bigint?: false; }): Promise<Stats>stat
methodstat(path: string, options: { bigint: true; }): Promise<BigIntStats>stat
methodstat(path: string, options?: { bigint?: boolean; }): Promise<Stats | BigIntStats>unlink
methodunlink(path: string): Promise<void>
rmdir
methodrmdir(path: string, options?: { recursive?: boolean; }): Promise<void>init
methodinit(options?: { encoding?: string; handle?: FileSystemDirectoryHandle; id?: string; name?: string; rootPath?: string; }): Promise<void>appendFile
methodappendFile(path: string, data: Buffer | string | Uint8Array, options?: { encoding?: BufferEncoding; mode?: number; flag?: string; }): Promise<void>copyFile
methodcopyFile(src: string, dest: string, mode?: number): Promise<void>
lstat
methodlstat(path: string, options?: { bigint?: false; }): Promise<Stats>lstat
methodlstat(path: string, options: { bigint: true; }): Promise<BigIntStats>lstat
methodlstat(path: string, options?: { bigint?: boolean; }): Promise<Stats | BigIntStats>rename
methodrename(oldPath: string, newPath: string): Promise<void>
access
methodaccess(path: string, mode?: number): Promise<void>
rm
methodrm(path: string, options?: { force?: boolean; maxRetries?: number; recursive?: boolean; retryDelay?: number; }): Promise<void>cp
methodcp(src: string, dest: string, options?: { dereference?: boolean; errorOnExist?: boolean; filter?: (src: string, dest: string) => boolean | Promise<boolean>; force?: boolean; mode?: number; preserveTimestamps?: boolean; recursive?: boolean; verbatimSymlinks?: boolean; }): Promise<void>mkdtemp
methodmkdtemp(prefix: string, options?: { encoding?: BufferEncoding; }): Promise<string>opendir
methodopendir(path: string, options?: { encoding?: BufferEncoding; bufferSize?: number; recursive?: boolean; }): Promise<IDir>open
methodopen(path: string, flags?: string | number, mode?: number): Promise<IFileHandle>
realpath
methodrealpath(path: string, options?: { encoding?: BufferEncoding; }): Promise<string>statfs
methodstatfs(path: string, options?: { bigint?: false; }): Promise<StatFs>statfs
methodstatfs(path: string, options: { bigint: true; }): Promise<BigIntStatFs>statfs
methodstatfs(path: string, options?: { bigint?: boolean; }): Promise<StatFs | BigIntStatFs>lutimes
methodlutimes(path: string, atime: string | number | Date, mtime: string | number | Date): Promise<void>
lchown
methodlchown(path: string, uid: number, gid: number): Promise<void>
lchmod
methodlchmod(path: string, mode: string | number): Promise<void>
truncate
methodtruncate(path: string, len?: number): Promise<void>
utimes
methodutimes(path: string, atime: string | number | Date, mtime: string | number | Date): Promise<void>
chmod
methodchmod(path: string, mode: string | number): Promise<void>
chown
methodchown(path: string, uid: number, gid: number): Promise<void>
readlink
methodreadlink(path: string, options?: { encoding?: BufferEncoding; }): Promise<string>symlink
methodsymlink(target: string, path: string, type?: "dir" | "file" | "junction"): Promise<void>
link
methodlink(existingPath: string, newPath: string): Promise<void>
isImplemented
methodisImplemented(feature: string): boolean
createReadStream
methodcreateReadStream(path: string, options?: { encoding?: BufferEncoding; start?: number; end?: number; }): ReadStreamcreateWriteStream
methodcreateWriteStream(path: string, options?: { encoding?: BufferEncoding; flags?: string; mode?: number; }): WriteStreamwatch
methodwatch(path: string, options?: { encoding?: BufferEncoding; persistent?: boolean; recursive?: boolean; }): FSWatcherdefault
classFactory for creating BrowserFileSystemImplementation instances This factory provides methods to create file systems either by showing a directory picker to the user or by reusing a previously saved handle.
class default
getInstance
methodGet the singleton instance of the factory
getInstance(): BrowserFileSystemFactory
debugDumpDatabase
methodDebug method to dump database contents for diagnostics
debugDumpDatabase(): Promise<void>
getAllHandleInfos
methodGet all stored handle info objects
getAllHandleInfos(): Promise<BrowserFsHandleInfo[]>
updateLastAccessed
methodUpdate the last accessed timestamp for a handle
updateLastAccessed(id: string): Promise<void>
saveHandleWithId
methodSave a file system with a specified ID
saveHandleWithId(id: string, name: string, fs: BrowserFileSystemImplementation): Promise<BrowserFsHandleInfo>
removeHandle
methodRemove a handle from storage
removeHandle(id: string): Promise<void>
createFromPicker
methodCreate a browser file system by showing a directory picker to the user
createFromPicker(options?: { encoding?: string; }, pickerOptions?: { id?: string; name?: string; startIn?: FileSystemHandle | "desktop" | "documents" | "downloads" | "music" | "pictures" | "videos"; mode?: "read" | "readwrite"; }): Promise<[BrowserFileSystemImplementation, BrowserFsHandleInfo]>createFromHandleInfo
methodCreate a browser file system from a previously saved handle
createFromHandleInfo(id: string, options?: { encoding?: string; }): Promise<BrowserFileSystemImplementation | null>Functions
isFileSystemAccessAPISupported
functionChecks if the File System Access API is available in the current browser
isFileSystemAccessAPISupported(): boolean
checkCapabilities
functionChecks if the File System Access API has specific capabilities
checkCapabilities(): { directoryHandle: boolean; fileHandle: boolean; writableFileStream: boolean; }pathToHandles
functionConvert a path to parent directory handle and file/directory name
pathToHandles(rootHandle: FileSystemDirectoryHandle, path: string, createParents?: boolean): Promise<{ parent: FileSystemDirectoryHandle; name: string; }>createBuffer
functionCreate a Buffer from an ArrayBuffer
createBuffer(arrayBuffer: ArrayBuffer): Buffer
convertToRelativePath
functionConvert an absolute path to a path relative to the root
convertToRelativePath(path: string): string
createLogger
functioncreateLogger(prefix: string, color: string): { info: (message: string, ...args: any[]) => void; error: (message: string, ...args: any[]) => void; warn: (message: string, ...args: any[]) => void; debug: (message: string, ...args: any[]) => void; table: (data: any, message?: string) => void; }createStatsObject
functionCreate a complete Stats object for browser filesystem
createStatsObject(options: CreateStatsOptions): Stats
createDirentObject
functionCreate a Dirent object for browser filesystem
createDirentObject(name: string, kind: "file" | "directory"): Dirent
initializeDatabase
functionInitialize IndexedDB for storing directory handles
initializeDatabase(): Promise<IDBDatabase>
saveDirectoryHandle
functionSave a directory handle to IndexedDB
saveDirectoryHandle(db: IDBDatabase, id: string, name: string, handle: FileSystemDirectoryHandle, path?: string): Promise<BrowserFsHandleInfo>
getDirectoryHandle
functionRetrieve a handle from IndexedDB
getDirectoryHandle(db: IDBDatabase, id: string): Promise<FileSystemDirectoryHandle | null>
getAllHandleInfos
functionGet all stored handle info objects
getAllHandleInfos(db: IDBDatabase): Promise<BrowserFsHandleInfo[]>
updateLastAccessedTimestamp
functionUpdate the last accessed timestamp for a handle
updateLastAccessedTimestamp(db: IDBDatabase, id: string): Promise<void>
removeDirectoryHandle
functionRemove a handle from storage
removeDirectoryHandle(db: IDBDatabase, id: string): Promise<void>
getFullHandleInfo
functionGet the full handle info record from IndexedDB
getFullHandleInfo(db: IDBDatabase, id: string): Promise<{ id: string; name: string; path?: string; handle: FileSystemDirectoryHandle; lastAccessed: number; version: string; } | null>Types
BrowserFsInfo
typetype BrowserFsInfo = { version?: "1.0.0"; id?: string; name?: string; rootPath?: string; }BrowserFsHandleInfo
typetype BrowserFsHandleInfo = { version?: "1.0.0"; path?: string; id?: string; name?: string; lastAccessed?: number; }Constants
browserFsInfoSchema
constconst browserFsInfoSchema: z.ZodObject<{ version: z.ZodLiteral<"1.0.0">; id: z.ZodString; name: z.ZodString; rootPath: z.ZodOptional<z.ZodString>; }, "strip", z.ZodTypeAny, { version?: "1.0.0"; id?: string; name?: string; rootPath?: string; }, { version?: "1.0.0"; id?: string; name?: string; rootPath?: string; }>browserFsHandleInfoSchema
constconst browserFsHandleInfoSchema: z.ZodObject<{ version: z.ZodLiteral<"1.0.0">; id: z.ZodString; name: z.ZodString; path: z.ZodOptional<z.ZodString>; lastAccessed: z.ZodNumber; }, "strip", z.ZodTypeAny, { version?: "1.0.0"; path?: string; id?: string; name?: string; lastAccessed?: number; }, { version?: "1.0.0"; path?: string; id?: string; name?: string; lastAccessed?: number; }>implementationLogger
constconst implementationLogger: { info: (message: string, ...args: any[]) => void; error: (message: string, ...args: any[]) => void; warn: (message: string, ...args: any[]) => void; debug: (message: string, ...args: any[]) => void; table: (data: any, message?: string) => void; }factoryLogger
constconst factoryLogger: { info: (message: string, ...args: any[]) => void; error: (message: string, ...args: any[]) => void; warn: (message: string, ...args: any[]) => void; debug: (message: string, ...args: any[]) => void; table: (data: any, message?: string) => void; }