Skip to content

Documentation / base / NullVFS

Class: NullVFS

Defined in: libs/base/src/vfs/nullfs.ts:8

Null file system.

Extends

Constructors

Constructor

new NullVFS(readonly?): NullVFS

Defined in: libs/base/src/vfs/nullfs.ts:10

Parameters

readonly?

boolean = false

Returns

NullVFS

Overrides

VFS.constructor

Properties

_readOnly

protected _readOnly: boolean

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

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: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

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

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


_makeDirectory()

protected _makeDirectory(): Promise<void>

Defined in: libs/base/src/vfs/nullfs.ts:15

Creates a directory in the file system.

Returns

Promise<void>

Overrides

VFS._makeDirectory


_readDirectory()

protected _readDirectory(): Promise<any[]>

Defined in: libs/base/src/vfs/nullfs.ts:17

Reads the contents of a directory from the file system.

Returns

Promise<any[]>

List of FileMetadata for entries in the directory

Overrides

VFS._readDirectory


_deleteDirectory()

protected _deleteDirectory(): Promise<void>

Defined in: libs/base/src/vfs/nullfs.ts:21

Deletes a directory and its contents (if recursive).

Returns

Promise<void>

Overrides

VFS._deleteDirectory


_readFile()

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

Defined in: libs/base/src/vfs/nullfs.ts:23

Reads a file from the file system.

Parameters

path

string

Path to file

Returns

Promise<string | ArrayBuffer>

File contents as ArrayBuffer or string

Overrides

VFS._readFile


_writeFile()

protected _writeFile(): Promise<void>

Defined in: libs/base/src/vfs/nullfs.ts:27

Writes data to a file (or stages for writing in memory).

Returns

Promise<void>

Overrides

VFS._writeFile


_deleteFile()

protected _deleteFile(): Promise<void>

Defined in: libs/base/src/vfs/nullfs.ts:29

Deletes a file in the file system.

Returns

Promise<void>

Overrides

VFS._deleteFile


_exists()

protected _exists(path): Promise<boolean>

Defined in: libs/base/src/vfs/nullfs.ts:31

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; }>

Defined in: libs/base/src/vfs/nullfs.ts:35

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; }>

FileStat (type, size, times, etc)

Overrides

VFS._stat


_deleteFileSystem()

protected _deleteFileSystem(): Promise<void>

Defined in: libs/base/src/vfs/nullfs.ts:47

Returns

Promise<void>

Overrides

VFS._deleteFileSystem


_wipe()

protected _wipe(): Promise<void>

Defined in: libs/base/src/vfs/nullfs.ts:50

Returns

Promise<void>

Overrides

VFS._wipe


_move()

protected _move(): Promise<void>

Defined in: libs/base/src/vfs/nullfs.ts:53

Moves/renames a file or directory within the same VFS. Implementation should avoid file copying and use metadata operations only.

Returns

Promise<void>

Overrides

VFS._move


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

VFS.getSimpleMountPoints


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

VFS.hasMounts


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

VFS.parseDataURI


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

VFS.isObjectURL


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

VFS.isAbsoluteURL


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

VFS.deleteFileSystem


wipe()

wipe(): Promise<void>

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

Delete entire database (for IndexedDB only).

Returns

Promise<void>

Inherited from

VFS.wipe


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

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: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

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: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

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: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

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: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

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: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

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:560

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: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

VFS.isAbsolute


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

VFS.basename


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

VFS.extname


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

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: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

VFS.isParentOf


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?

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:693

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:710

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:735

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:777

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:820

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:848

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: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

VFS.exists


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

VFS.stat


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?

VFS

Returns

Promise<void>

Inherited from

VFS.copyFile


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?

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: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

VFS.glob


guessMIMEType()

guessMIMEType(path): string

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

Parameters

path

string

Returns

string

Inherited from

VFS.guessMIMEType


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

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:1250

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:1268

Closes file system and release resources

Returns

Promise<void>

Inherited from

VFS.close


onChange()

protected onChange(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

Inherited from

VFS.onChange

Released under the MIT License.