Documentation / base / IndexedDBFS
Class: IndexedDBFS
Defined in: libs/base/src/vfs/idbfs.ts:21
IndexedDB-based file system implementation.
Provides a virtual file system interface using IndexedDB as the underlying storage. Supports standard file operations like create, read, write, delete, and directory listing.
Example
const fs = new IndexedDBFS('my-app-fs');
await fs.writeFile('/hello.txt', 'Hello World!');
const content = await fs.readFile('/hello.txt', { encoding: 'utf8' });Extends
Constructors
Constructor
new IndexedDBFS(
dbName,storeName,readonly?):IndexedDBFS
Defined in: libs/base/src/vfs/idbfs.ts:32
Creates a new IndexedDB file system.
Parameters
dbName
string
The name of the IndexedDB database to use
storeName
string
readonly?
boolean = false
Whether the file system should be read-only
Returns
IndexedDBFS
Overrides
Properties
_readOnly
protected_readOnly:boolean
Defined in: libs/base/src/vfs/vfs.ts:318
Whether this file system is read-only
Inherited from
Accessors
readOnly
Get Signature
get readOnly():
boolean
Defined in: libs/base/src/vfs/vfs.ts:348
Toggle readonly
Returns
boolean
Set Signature
set readOnly(
val):void
Defined in: libs/base/src/vfs/vfs.ts:351
Parameters
val
boolean
Returns
void
Inherited from
Methods
on()
on<
K>(type,listener,context?):void
Defined in: libs/base/src/event.ts:104
Sets up a function that will be called whenever the specified event is delivered to the target
Type Parameters
K
K extends "changed"
Parameters
type
K
The event type to listen for
listener
EventListener<{ changed: ["created" | "deleted" | "moved" | "modified", string, "file" | "directory"]; }, K>
The callback function
context?
unknown
Context object of the listener function
Returns
void
Inherited from
once()
once<
K>(type,listener,context?):void
Defined in: libs/base/src/event.ts:117
Sets up a function that will be called only once when the specified event is delivered to the target
Type Parameters
K
K extends "changed"
Parameters
type
K
The event type to listen for
listener
EventListener<{ changed: ["created" | "deleted" | "moved" | "modified", string, "file" | "directory"]; }, K>
The callback function
context?
unknown
Context object of the listener function
Returns
void
Inherited from
off()
off<
K>(type,listener?,context?):void
Defined in: libs/base/src/event.ts:130
Removes an event listener function previously registered.
Type Parameters
K
K extends "changed"
Parameters
type
K
The event type for which to remove an event listener
listener?
EventListener<{ changed: ["created" | "deleted" | "moved" | "modified", string, "file" | "directory"]; }>
The callback function to be removed
context?
unknown
Returns
void
Inherited from
dispatchEvent()
dispatchEvent<
K>(type, ...args):void
Defined in: libs/base/src/event.ts:138
Synchronously invoke the affected event listeners with an event object
Type Parameters
K
K extends "changed"
Parameters
type
K
args
...object[K]
Returns
void
false if the event was canceled, otherwise true
Inherited from
_makeDirectory()
protected_makeDirectory(path,recursive):Promise<void>
Defined in: libs/base/src/vfs/idbfs.ts:38
Creates a directory in the file system.
Parameters
path
string
Directory path
recursive
boolean
Whether to create parent directories
Returns
Promise<void>
Overrides
_readDirectory()
protected_readDirectory(path,options?):Promise<FileMetadata[]>
Defined in: libs/base/src/vfs/idbfs.ts:96
Reads the contents of a directory from the file system.
Parameters
path
string
Directory path
options?
Listing options (recursive, filter, etc)
Returns
Promise<FileMetadata[]>
List of FileMetadata for entries in the directory
Overrides
_deleteDirectory()
protected_deleteDirectory(path,recursive):Promise<void>
Defined in: libs/base/src/vfs/idbfs.ts:170
Deletes a directory and its contents (if recursive).
Parameters
path
string
Directory path
recursive
boolean
If true, delete contents recursively
Returns
Promise<void>
Overrides
_readFile()
protected_readFile(path,options?):Promise<string|ArrayBuffer>
Defined in: libs/base/src/vfs/idbfs.ts:206
Reads a file from the file system.
Parameters
path
string
Path to file
options?
Read options (encoding, offset, length)
Returns
Promise<string | ArrayBuffer>
File contents as ArrayBuffer or string
Overrides
_writeFile()
protected_writeFile(path,data,options?):Promise<void>
Defined in: libs/base/src/vfs/idbfs.ts:260
Writes data to a file (or stages for writing in memory).
Parameters
path
string
File path
data
string | ArrayBuffer
Data to write
options?
Write options (append, encoding, create parent dirs)
Returns
Promise<void>
Overrides
_deleteFile()
protected_deleteFile(path):Promise<void>
Defined in: libs/base/src/vfs/idbfs.ts:337
Deletes a file in the file system.
Parameters
path
string
File path
Returns
Promise<void>
Overrides
_exists()
protected_exists(path):Promise<boolean>
Defined in: libs/base/src/vfs/idbfs.ts:358
Checks if a file or directory exists in the file system.
Parameters
path
string
File or directory path
Returns
Promise<boolean>
True if exists
Overrides
_stat()
protected_stat(path):Promise<FileStat>
Defined in: libs/base/src/vfs/idbfs.ts:370
Gets statistics/metadata for a file or directory.
Parameters
path
string
File or directory path
Returns
Promise<FileStat>
FileStat (type, size, times, etc)
Overrides
deleteDatabase()
staticdeleteDatabase(name):Promise<void>
Defined in: libs/base/src/vfs/idbfs.ts:402
Parameters
name
string
Returns
Promise<void>
_wipe()
protected_wipe():Promise<void>
Defined in: libs/base/src/vfs/idbfs.ts:421
Returns
Promise<void>
Overrides
_deleteFileSystem()
protected_deleteFileSystem():Promise<void>
Defined in: libs/base/src/vfs/idbfs.ts:425
Returns
Promise<void>
Overrides
_move()
protected_move(sourcePath,targetPath,options?):Promise<void>
Defined in: libs/base/src/vfs/idbfs.ts:464
Moves/renames a file or directory within the same VFS. Implementation should avoid file copying and use metadata operations only.
Parameters
sourcePath
string
Source path (normalized)
targetPath
string
Target path (normalized)
options?
Move options
Returns
Promise<void>
Overrides
getSimpleMountPoints()
getSimpleMountPoints():
string[]
Defined in: libs/base/src/vfs/vfs.ts:359
Gets all simple mount points.
Returns
string[]
Array of mount point paths
Inherited from
hasMounts()
hasMounts():
boolean
Defined in: libs/base/src/vfs/vfs.ts:368
Checks if this VFS has any mount points.
Returns
boolean
True if there are mounted VFS instances, false otherwise
Inherited from
parseDataURI()
parseDataURI(
uri):RegExpMatchArray
Defined in: libs/base/src/vfs/vfs.ts:377
Parse DataURL
Parameters
uri
string
URL to parse
Returns
RegExpMatchArray
parts of data URL
Inherited from
isObjectURL()
isObjectURL(
url):boolean
Defined in: libs/base/src/vfs/vfs.ts:385
Checks wether a URL is object url created by URL.createObjectURL()
Parameters
url
string
URL to check
Returns
boolean
true if the URL is object url, otherwise false
Inherited from
isAbsoluteURL()
isAbsoluteURL(
url):boolean
Defined in: libs/base/src/vfs/vfs.ts:393
Checks wether a URL is absolute URL
Parameters
url
string
URL to check
Returns
boolean
true if the URL is absolute URL, otherwise false
Inherited from
deleteFileSystem()
deleteFileSystem():
Promise<void>
Defined in: libs/base/src/vfs/vfs.ts:399
Disposes of this file system and cleans up resources. (for IndexedDB only).
Returns
Promise<void>
Inherited from
wipe()
wipe():
Promise<void>
Defined in: libs/base/src/vfs/vfs.ts:406
Delete entire database (for IndexedDB only).
Returns
Promise<void>
Inherited from
getCwd()
getCwd():
string
Defined in: libs/base/src/vfs/vfs.ts:421
Gets the current working directory.
Returns
string
The current working directory path
Example
const cwd = fs.getCwd();
console.log(`Current directory: ${cwd}`);Inherited from
chdir()
chdir(
path):Promise<void>
Defined in: libs/base/src/vfs/vfs.ts:437
Changes the current working directory.
Parameters
path
string
The new working directory path (absolute or relative)
Returns
Promise<void>
Promise that resolves when directory is changed
Example
await fs.chdir('/home/user');
await fs.chdir('../documents'); // Relative pathInherited from
pushd()
pushd(
path):Promise<void>
Defined in: libs/base/src/vfs/vfs.ts:466
Pushes the current directory onto the directory stack and changes to the specified directory.
Parameters
path
string
The directory to change to (absolute or relative)
Returns
Promise<void>
Promise that resolves when directory is changed
Example
await fs.pushd('/tmp'); // Push current dir and go to /tmp
await fs.pushd('../other'); // Push /tmp and go to /otherInherited from
popd()
popd():
Promise<void>
Defined in: libs/base/src/vfs/vfs.ts:482
Pops a directory from the directory stack and changes to it.
Returns
Promise<void>
Promise that resolves when directory is changed
Throws
VFSError if the directory stack is empty
Example
await fs.popd(); // Return to previously pushed directoryInherited from
normalizePath()
normalizePath(
path):string
Defined in: libs/base/src/vfs/vfs.ts:508
Normalizes a path, resolving . and .. components and making it absolute. Supports both absolute and relative paths.
Parameters
path
string
The path to normalize
Returns
string
The normalized absolute path
Example
// Assuming CWD is /home/user
fs.normalizePath('.'); // -> /home/user
fs.normalizePath('..'); // -> /home
fs.normalizePath('../docs'); // -> /home/docs
fs.normalizePath('/tmp'); // -> /tmp
fs.normalizePath('sub/dir'); // -> /home/user/sub/dirInherited from
join()
join(...
paths):string
Defined in: libs/base/src/vfs/vfs.ts:541
Join paths together, making the result relative to CWD if not absolute.
Parameters
paths
...string[]
Paths to join
Returns
string
Complete normalized path
Example
// Assuming CWD is /home/user
fs.join('docs', 'file.txt'); // -> /home/user/docs/file.txt
fs.join('/tmp', 'file.txt'); // -> /tmp/file.txtInherited from
dirname()
dirname(
path):string
Defined in: libs/base/src/vfs/vfs.ts:560
Extract directory part for a path
Parameters
path
string
path
Returns
string
Directory part of the path
Inherited from
isAbsolute()
isAbsolute(
path):boolean
Defined in: libs/base/src/vfs/vfs.ts:568
Returns whether a path is absolute or not
Parameters
path
string
path to check
Returns
boolean
true if the path is an absolute path
Inherited from
basename()
basename(
path,ext?):string
Defined in: libs/base/src/vfs/vfs.ts:577
Extract base file name part for a path
Parameters
path
string
path
ext?
string
Optional extension to strip (exact suffix match).
Returns
string
The base name of the path.
Inherited from
extname()
extname(
path):string
Defined in: libs/base/src/vfs/vfs.ts:585
Extract extension file name part for a path
Parameters
path
string
path
Returns
string
extension file name part of the path
Inherited from
relative()
relative(
path,parent?):string
Defined in: libs/base/src/vfs/vfs.ts:602
Converts an absolute path to a path relative to the current working directory.
Parameters
path
string
The absolute path to convert
parent?
string
Returns
string
The relative path from CWD
Example
// Assuming CWD is /home/user
fs.relative('/home/user/docs'); // -> docs
fs.relative('/home'); // -> ..
fs.relative('/tmp'); // -> ../../tmpInherited from
isParentOf()
isParentOf(
parentPath,path):boolean
Defined in: libs/base/src/vfs/vfs.ts:618
Determine whether parentPath is parent directory of path (includes the case where parentPath is same as path)
Parameters
parentPath
string
The possible parent path
path
string
The possible child path
Returns
boolean
true if parentPath is parent directory of path or parent directory is same as path
Inherited from
move()
move(
sourcePath,targetPath,options?):Promise<void>
Defined in: libs/base/src/vfs/vfs.ts:648
Moves/renames a file or directory.
Parameters
sourcePath
string
Source path
targetPath
string
Target path
options?
Move options
Returns
Promise<void>
Example
// Rename file
await fs.move('/old_name.txt', '/new_name.txt');
// Move file to directory
await fs.move('/file.txt', '/subdir/file.txt');
// Rename directory
await fs.move('/old_dir', '/new_dir');Inherited from
makeDirectory()
makeDirectory(
path,recursive?):Promise<void>
Defined in: libs/base/src/vfs/vfs.ts:693
Makes new directory
Parameters
path
string
Directory path
recursive?
boolean
If true, create parent directory if not exists
Returns
Promise<void>
Inherited from
readDirectory()
readDirectory(
path,options?):Promise<FileMetadata[]>
Defined in: libs/base/src/vfs/vfs.ts:710
Parameters
path
string
options?
Returns
Promise<FileMetadata[]>
Inherited from
deleteDirectory()
deleteDirectory(
path,recursive?):Promise<void>
Defined in: libs/base/src/vfs/vfs.ts:735
Parameters
path
string
recursive?
boolean
Returns
Promise<void>
Inherited from
readFile()
readFile(
path,options?):Promise<string|ArrayBuffer>
Defined in: libs/base/src/vfs/vfs.ts:777
Read from a VFS file
Parameters
path
string
File path to read
options?
Read options
Returns
Promise<string | ArrayBuffer>
The file contents
Inherited from
writeFile()
writeFile(
path,data,options?):Promise<void>
Defined in: libs/base/src/vfs/vfs.ts:820
Write to a VFS file
Parameters
path
string
File path to write
data
string | ArrayBuffer
Data to be written
options?
Write options
Returns
Promise<void>
Inherited from
deleteFile()
deleteFile(
path):Promise<void>
Defined in: libs/base/src/vfs/vfs.ts:848
Deletes a VFS file
Parameters
path
string
File path to delete
Returns
Promise<void>
Inherited from
exists()
exists(
path):Promise<boolean>
Defined in: libs/base/src/vfs/vfs.ts:870
Test whether a VFS file or directory exists for given path
Parameters
path
string
Path to test
Returns
Promise<boolean>
true if exists
Inherited from
stat()
stat(
path):Promise<FileStat>
Defined in: libs/base/src/vfs/vfs.ts:888
Gets the statistics about a given path
Parameters
path
string
path
Returns
Promise<FileStat>
Statistics about the path
Inherited from
copyFile()
copyFile(
src,dest,options?):Promise<void>
Defined in: libs/base/src/vfs/vfs.ts:913
Copies a VFS file
Parameters
src
string
Source file path
dest
string
Destination file path
options?
Copy options
overwrite?
boolean
targetVFS?
Returns
Promise<void>
Inherited from
copyFileEx()
copyFileEx(
sourcePattern,targetDirectory,options?):Promise<void>
Defined in: libs/base/src/vfs/vfs.ts:985
Copy multiple files matching a pattern to a target directory
Parameters
sourcePattern
string | string[]
Source pattern (glob pattern, file path, or array of file paths)
targetDirectory
string
Target directory path
options?
Copy options (can include targetVFS for cross-VFS copy)
cwd?
string
overwrite?
boolean
targetVFS?
onProgress?
(current, total) => void
Returns
Promise<void>
Copy operation result
Example
// Copy all .txt files to backup directory
const result = await vfs.copyFileEx('/data/*.txt', '/backup');
// Copy directory to different VFS
const result = await vfsA.copyFileEx('DirToCopy/**/*', 'Foo/DirToCopy', {
overwrite: true,
targetVFS: vfsB
});
// Copy specific files
const result = await vfs.copyFileEx(['/file1.txt', '/file2.txt'], '/backup');Inherited from
glob()
glob(
pattern,options?):Promise<GlobResult[]>
Defined in: libs/base/src/vfs/vfs.ts:1084
Query file list by matching pattern(s)
Parameters
pattern
string | string[]
Matching pattern(s)
options?
GlobOptions = {}
Matching options
Returns
Promise<GlobResult[]>
Informations of matching files
Inherited from
guessMIMEType()
guessMIMEType(
path):string
Defined in: libs/base/src/vfs/vfs.ts:1201
Parameters
path
string
Returns
string
Inherited from
mount()
mount(
path,vfs):Promise<void>
Defined in: libs/base/src/vfs/vfs.ts:1219
Mounts another VFS at the specified path.
Constraints/Behavior:
- Mount path can be an existing directory or non existing directory.
- Changes from child VFS will bubble to host namespace (path is rewritten with mount prefix)
Parameters
path
string
The path where to mount the VFS
vfs
The VFS instance to mount
Returns
Promise<void>
Inherited from
unmount()
unmount(
path):Promise<boolean>
Defined in: libs/base/src/vfs/vfs.ts:1250
Unmounts a VFS from the specified path.
Behavior:
- Removes the mount record.
- If the mount directory was auto-created by this VFS and
cleanupOnUnmountis true, it will be removed only if it is still empty.
Parameters
path
string
The path to unmount
Returns
Promise<boolean>
True if a VFS was unmounted, false otherwise
Inherited from
close()
close():
Promise<void>
Defined in: libs/base/src/vfs/vfs.ts:1268
Closes file system and release resources
Returns
Promise<void>
Inherited from
onChange()
protectedonChange(type,path,itemType):void
Defined in: libs/base/src/vfs/vfs.ts:1315
VFS file changing event
Parameters
type
"created" | "deleted" | "moved" | "modified"
Change type
path
string
File path that causes changing
itemType
"file" | "directory"
File type
Returns
void