Skip to content

Documentation / base / DataTransferVFS

Class: DataTransferVFS ​

Defined in: libs/base/src/vfs/datatransferfs.ts:40

DataTransfer-based virtual file system for handling dropped files and directories.

Read-only VFS populated from a DataTransfer (drag-and-drop) or a FileList (e.g., from <input type="file" webkitdirectory>).

Notes:

  • This VFS is read-only; mutating operations throw VFSError with code "EROFS".
  • For directory support via drag-and-drop, relies on non-standard WebKit APIs (webkitGetAsEntry, FileSystemDirectoryEntry, etc.) where available.

Extends ​

Constructors ​

Constructor ​

new DataTransferVFS(data): DataTransferVFS

Defined in: libs/base/src/vfs/datatransferfs.ts:54

Constructs a read-only VFS from DataTransfer or FileList.

Initialization is asynchronous. Public operations wait for completion via an internal gate (ensureInitialized).

Parameters ​

data ​

DataTransfer | FileList

The source of files/directories (drag-and-drop DataTransfer or FileList).

Returns ​

DataTransferVFS

Overrides ​

VFS.constructor

Properties ​

_readOnly ​

protected _readOnly: boolean

Defined in: libs/base/src/vfs/vfs.ts:323

Whether this file system is read-only

Inherited from ​

VFS._readOnly

Accessors ​

readOnly ​

Get Signature ​

get readOnly(): boolean

Defined in: libs/base/src/vfs/vfs.ts:358

Toggle readonly

Returns ​

boolean

Set Signature ​

set readOnly(val): void

Defined in: libs/base/src/vfs/vfs.ts:361

Parameters ​
val ​

boolean

Returns ​

void

Inherited from ​

VFS.readOnly

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", string]; }, K>

The callback function

context? ​

unknown

Context object of the listener function

Returns ​

void

Inherited from ​

VFS.on


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", string]; }, K>

The callback function

context? ​

unknown

Context object of the listener function

Returns ​

void

Inherited from ​

VFS.once


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", string]; }>

The callback function to be removed

context? ​

unknown

Returns ​

void

Inherited from ​

VFS.off


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 ​

VFS.dispatchEvent


_readDirectory() ​

protected _readDirectory(path, options?): Promise<FileMetadata[]>

Defined in: libs/base/src/vfs/datatransferfs.ts:71

Reads the contents of a directory from the file system.

Parameters ​

path ​

string

Directory path

options? ​

ListOptions

Listing options (recursive, filter, etc)

Returns ​

Promise<FileMetadata[]>

List of FileMetadata for entries in the directory

Overrides ​

VFS._readDirectory


_readFile() ​

protected _readFile(path, options?): Promise<string | ArrayBuffer>

Defined in: libs/base/src/vfs/datatransferfs.ts:125

Reads a file from the file system.

Parameters ​

path ​

string

Path to file

options? ​

ReadOptions

Read options (encoding, offset, length)

Returns ​

Promise<string | ArrayBuffer>

File contents as ArrayBuffer or string

Overrides ​

VFS._readFile


_exists() ​

protected _exists(path): Promise<boolean>

Defined in: libs/base/src/vfs/datatransferfs.ts:159

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 ​

VFS._exists


_stat() ​

protected _stat(path): Promise<{ size: number; isFile: boolean; isDirectory: boolean; created: Date; modified: Date; accessed: Date; }>

Defined in: libs/base/src/vfs/datatransferfs.ts:173

Gets statistics/metadata for a file or directory.

Parameters ​

path ​

string

File or directory path

Returns ​

Promise<{ size: number; isFile: boolean; isDirectory: boolean; created: Date; modified: Date; accessed: Date; }>

FileStat (type, size, times, etc)

Overrides ​

VFS._stat


_writeFile() ​

protected _writeFile(): Promise<void>

Defined in: libs/base/src/vfs/datatransferfs.ts:208

Not supported. DataTransfer VFS is read-only.

Returns ​

Promise<void>

Throws ​

VFSError with code "EROFS".

Overrides ​

VFS._writeFile


_makeDirectory() ​

protected _makeDirectory(): Promise<void>

Defined in: libs/base/src/vfs/datatransferfs.ts:215

Not supported. DataTransfer VFS is read-only.

Returns ​

Promise<void>

Throws ​

VFSError with code "EROFS".

Overrides ​

VFS._makeDirectory


_deleteFile() ​

protected _deleteFile(): Promise<void>

Defined in: libs/base/src/vfs/datatransferfs.ts:222

Not supported. DataTransfer VFS is read-only.

Returns ​

Promise<void>

Throws ​

VFSError with code "EROFS".

Overrides ​

VFS._deleteFile


_deleteDirectory() ​

protected _deleteDirectory(): Promise<void>

Defined in: libs/base/src/vfs/datatransferfs.ts:229

Not supported. DataTransfer VFS is read-only.

Returns ​

Promise<void>

Throws ​

VFSError with code "EROFS".

Overrides ​

VFS._deleteDirectory


_wipe() ​

protected _wipe(): Promise<void>

Defined in: libs/base/src/vfs/datatransferfs.ts:235

No-op for read-only VFS.

Returns ​

Promise<void>

Overrides ​

VFS._wipe


_deleteFileSystem() ​

protected _deleteFileSystem(): Promise<void>

Defined in: libs/base/src/vfs/datatransferfs.ts:241

No-op for read-only VFS.

Returns ​

Promise<void>

Overrides ​

VFS._deleteFileSystem


_move() ​

protected _move(): Promise<void>

Defined in: libs/base/src/vfs/datatransferfs.ts:247

No-op for read-only VFS.

Returns ​

Promise<void>

Overrides ​

VFS._move


getSimpleMountPoints() ​

getSimpleMountPoints(): string[]

Defined in: libs/base/src/vfs/vfs.ts:369

Gets all simple mount points.

Returns ​

string[]

Array of mount point paths

Inherited from ​

VFS.getSimpleMountPoints


hasMounts() ​

hasMounts(): boolean

Defined in: libs/base/src/vfs/vfs.ts:378

Checks if this VFS has any mount points.

Returns ​

boolean

True if there are mounted VFS instances, false otherwise

Inherited from ​

VFS.hasMounts


parseDataURI() ​

parseDataURI(uri): RegExpMatchArray

Defined in: libs/base/src/vfs/vfs.ts:387

Parse DataURL

Parameters ​

uri ​

string

URL to parse

Returns ​

RegExpMatchArray

parts of data URL

Inherited from ​

VFS.parseDataURI


isObjectURL() ​

isObjectURL(url): boolean

Defined in: libs/base/src/vfs/vfs.ts:395

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 ​

VFS.isObjectURL


isAbsoluteURL() ​

isAbsoluteURL(url): boolean

Defined in: libs/base/src/vfs/vfs.ts:403

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 ​

VFS.isAbsoluteURL


deleteFileSystem() ​

deleteFileSystem(): Promise<void>

Defined in: libs/base/src/vfs/vfs.ts:409

Disposes of this file system and cleans up resources. (for IndexedDB only).

Returns ​

Promise<void>

Inherited from ​

VFS.deleteFileSystem


wipe() ​

wipe(): Promise<void>

Defined in: libs/base/src/vfs/vfs.ts:416

Delete entire database (for IndexedDB only).

Returns ​

Promise<void>

Inherited from ​

VFS.wipe


getCwd() ​

getCwd(): string

Defined in: libs/base/src/vfs/vfs.ts:431

Gets the current working directory.

Returns ​

string

The current working directory path

Example ​

typescript
const cwd = fs.getCwd();
console.log(`Current directory: ${cwd}`);

Inherited from ​

VFS.getCwd


chdir() ​

chdir(path): Promise<void>

Defined in: libs/base/src/vfs/vfs.ts:447

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 ​

typescript
await fs.chdir('/home/user');
await fs.chdir('../documents'); // Relative path

Inherited from ​

VFS.chdir


pushd() ​

pushd(path): Promise<void>

Defined in: libs/base/src/vfs/vfs.ts:476

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 ​

typescript
await fs.pushd('/tmp');        // Push current dir and go to /tmp
await fs.pushd('../other');    // Push /tmp and go to /other

Inherited from ​

VFS.pushd


popd() ​

popd(): Promise<void>

Defined in: libs/base/src/vfs/vfs.ts:492

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 ​

typescript
await fs.popd(); // Return to previously pushed directory

Inherited from ​

VFS.popd


normalizePath() ​

normalizePath(path): string

Defined in: libs/base/src/vfs/vfs.ts:518

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 ​

typescript
// 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/dir

Inherited from ​

VFS.normalizePath


join() ​

join(...paths): string

Defined in: libs/base/src/vfs/vfs.ts:551

Join paths together, making the result relative to CWD if not absolute.

Parameters ​

paths ​

...string[]

Paths to join

Returns ​

string

Complete normalized path

Example ​

typescript
// Assuming CWD is /home/user
fs.join('docs', 'file.txt');     // -> /home/user/docs/file.txt
fs.join('/tmp', 'file.txt');     // -> /tmp/file.txt

Inherited from ​

VFS.join


dirname() ​

dirname(path): string

Defined in: libs/base/src/vfs/vfs.ts:570

Extract directory part for a path

Parameters ​

path ​

string

path

Returns ​

string

Directory part of the path

Inherited from ​

VFS.dirname


isAbsolute() ​

isAbsolute(path): boolean

Defined in: libs/base/src/vfs/vfs.ts:578

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 ​

VFS.isAbsolute


basename() ​

basename(path, ext?): string

Defined in: libs/base/src/vfs/vfs.ts:587

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 ​

VFS.basename


extname() ​

extname(path): string

Defined in: libs/base/src/vfs/vfs.ts:595

Extract extension file name part for a path

Parameters ​

path ​

string

path

Returns ​

string

extension file name part of the path

Inherited from ​

VFS.extname


relative() ​

relative(path, parent?): string

Defined in: libs/base/src/vfs/vfs.ts:612

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 ​

typescript
// Assuming CWD is /home/user
fs.relative('/home/user/docs');  // -> docs
fs.relative('/home');            // -> ..
fs.relative('/tmp');             // -> ../../tmp

Inherited from ​

VFS.relative


isParentOf() ​

isParentOf(parentPath, path): boolean

Defined in: libs/base/src/vfs/vfs.ts:628

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 ​

VFS.isParentOf


move() ​

move(sourcePath, targetPath, options?): Promise<void>

Defined in: libs/base/src/vfs/vfs.ts:658

Moves/renames a file or directory.

Parameters ​

sourcePath ​

string

Source path

targetPath ​

string

Target path

options? ​

MoveOptions

Move options

Returns ​

Promise<void>

Example ​

typescript
// 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 ​

VFS.move


makeDirectory() ​

makeDirectory(path, recursive?): Promise<void>

Defined in: libs/base/src/vfs/vfs.ts:703

Makes new directory

Parameters ​

path ​

string

Directory path

recursive? ​

boolean

If true, create parent directory if not exists

Returns ​

Promise<void>

Inherited from ​

VFS.makeDirectory


readDirectory() ​

readDirectory(path, options?): Promise<FileMetadata[]>

Defined in: libs/base/src/vfs/vfs.ts:720

Parameters ​

path ​

string

options? ​

ListOptions

Returns ​

Promise<FileMetadata[]>

Inherited from ​

VFS.readDirectory


deleteDirectory() ​

deleteDirectory(path, recursive?): Promise<void>

Defined in: libs/base/src/vfs/vfs.ts:745

Parameters ​

path ​

string

recursive? ​

boolean

Returns ​

Promise<void>

Inherited from ​

VFS.deleteDirectory


readFile() ​

readFile(path, options?): Promise<string | ArrayBuffer>

Defined in: libs/base/src/vfs/vfs.ts:787

Read from a VFS file

Parameters ​

path ​

string

File path to read

options? ​

ReadOptions

Read options

Returns ​

Promise<string | ArrayBuffer>

The file contents

Inherited from ​

VFS.readFile


writeFile() ​

writeFile(path, data, options?): Promise<void>

Defined in: libs/base/src/vfs/vfs.ts:830

Write to a VFS file

Parameters ​

path ​

string

File path to write

data ​

string | ArrayBuffer

Data to be written

options? ​

WriteOptions

Write options

Returns ​

Promise<void>

Inherited from ​

VFS.writeFile


deleteFile() ​

deleteFile(path): Promise<void>

Defined in: libs/base/src/vfs/vfs.ts:858

Deletes a VFS file

Parameters ​

path ​

string

File path to delete

Returns ​

Promise<void>

Inherited from ​

VFS.deleteFile


exists() ​

exists(path): Promise<boolean>

Defined in: libs/base/src/vfs/vfs.ts:880

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 ​

VFS.exists


stat() ​

stat(path): Promise<FileStat>

Defined in: libs/base/src/vfs/vfs.ts:898

Gets the statistics about a given path

Parameters ​

path ​

string

path

Returns ​

Promise<FileStat>

Statistics about the path

Inherited from ​

VFS.stat


copyFile() ​

copyFile(src, dest, options?): Promise<void>

Defined in: libs/base/src/vfs/vfs.ts:923

Copies a VFS file

Parameters ​

src ​

string

Source file path

dest ​

string

Destination file path

options? ​

Copy options

overwrite? ​

boolean

targetVFS? ​

VFS

Returns ​

Promise<void>

Inherited from ​

VFS.copyFile


copyFileEx() ​

copyFileEx(sourcePattern, targetDirectory, options?): Promise<void>

Defined in: libs/base/src/vfs/vfs.ts:995

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? ​

VFS

onProgress? ​

(current, total) => void

Returns ​

Promise<void>

Copy operation result

Example ​

typescript
// 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 ​

VFS.copyFileEx


glob() ​

glob(pattern, options?): Promise<GlobResult[]>

Defined in: libs/base/src/vfs/vfs.ts:1094

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 ​

VFS.glob


guessMIMEType() ​

guessMIMEType(path): string

Defined in: libs/base/src/vfs/vfs.ts:1211

Parameters ​

path ​

string

Returns ​

string

Inherited from ​

VFS.guessMIMEType


mount() ​

mount(path, vfs): Promise<void>

Defined in: libs/base/src/vfs/vfs.ts:1229

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 ​

VFS

The VFS instance to mount

Returns ​

Promise<void>

Inherited from ​

VFS.mount


unmount() ​

unmount(path): Promise<boolean>

Defined in: libs/base/src/vfs/vfs.ts:1264

Unmounts a VFS from the specified path.

Behavior:

  • Removes the mount record.
  • If the mount directory was auto-created by this VFS and cleanupOnUnmount is 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 ​

VFS.unmount


close() ​

close(): Promise<void>

Defined in: libs/base/src/vfs/vfs.ts:1282

Closes file system and release resources

Returns ​

Promise<void>

Inherited from ​

VFS.close


onChange() ​

protected onChange(type, path, itemType, oldPath?): void

Defined in: libs/base/src/vfs/vfs.ts:1330

VFS file changing event

Parameters ​

type ​

"created" | "deleted" | "moved" | "modified"

Change type

path ​

string

File path that causes changing

itemType ​

"file" | "directory"

File type

oldPath? ​

string

Previous path for move operations, when available

Returns ​

void

Inherited from ​

VFS.onChange

Released under the MIT License.