Skip to content

Class: MockFileSystem ​

Mock engine FS manager.

Implements ​

  • FS

Constructors ​

Constructor ​

ts
new MockFileSystem(mocks?: Record<string, any>): MockFileSystem;

Parameters ​

ParameterTypeDefault value
mocksRecord<string, any>MockFileSystem.MOCKS

Returns ​

MockFileSystem

Methods ​

setMock() ​

ts
setMock(
   root: string, 
   path: string, 
   isExisting?: boolean): void;

Parameters ​

ParameterTypeDefault value
rootstringundefined
pathstringundefined
isExistingbooleantrue

Returns ​

void


setMockRoot() ​

ts
setMockRoot(root: string, isExisting?: boolean): void;

Mark a whole root as existing, so any unmocked path under it resolves as present. A specific setMock(root, path, false) still wins over the permissive default.

Parameters ​

ParameterTypeDefault valueDescription
rootstringundefinedFilesystem alias to treat as populated.
isExistingbooleantrueWhether files under the root should resolve as present.

Returns ​

void


create() ​

ts
static create(mocks?: Record<string, any>): MockFileSystem;

Parameters ​

ParameterTypeDefault value
mocksRecord<string, any>MockFileSystem.MOCKS

Returns ​

MockFileSystem


getInstance() ​

ts
static getInstance(): MockFileSystem;

Returns ​

MockFileSystem


mock() ​

ts
static mock(): MockFileSystem;

Returns ​

MockFileSystem

Properties ​

append_path ​

ts
append_path: Mock<(alias: string, root: string, add: string) => {
  m_Add: string;
  m_DefExt: string;
  m_FilterCaption: string;
  m_Path: string;
  m_Root: string;
}>;

Add a path alias.

Remarks ​

Native code asserts if root is invalid or alias is already registered. On success it returns a path descriptor.

Param ​

alias

Alias name.

Param ​

root

Root path.

Param ​

path

Relative path.

Param ​

recursive

Whether subfolders should be scanned.

Returns ​

Native filesystem path descriptor.

Implementation of ​

ts
FS.append_path

dir_delete ​

ts
dir_delete: Mock<() => void>;

Delete a directory below a path alias.

Param ​

path

Path alias or root path.

Param ​

filename

Directory name.

Param ​

remove_files

Whether files inside should be removed.

Implementation of ​

ts
FS.dir_delete

exist ​

ts
exist: MockedFunction<{
  (alias: string, filename: string, fs_type: TXR_fs_type): FileStatus;
  (alias: string, filename: string): Nullable<fs_file>;
  (path: string): Nullable<fs_file>;
  (path: string, fs_type: TXR_fs_type): FileStatus;
}>;

Check whether a file exists below a path alias in a selected filesystem source.

Since ​

OpenXRay 2014-11-02, 827c9f58

Remarks ​

OpenXRay extension. This overload resolves alias and filename, then checks virtual files, external files, or both according to fs_type. It always returns a FileStatus; inspect Exists for the result and External to see whether the match came from the external filesystem.

Param ​

alias

Filesystem path alias.

Param ​

filename

File name.

Param ​

fs_type

Filesystem source to search.

Returns ​

File status.

Implementation of ​

ts
FS.exist

file_copy ​

ts
file_copy: Mock<() => void>;

Copy a file.

Param ​

source

Source file path.

Param ​

destination

Destination file path.

Implementation of ​

ts
FS.file_copy

file_delete ​

ts
file_delete: Mock<() => void>;

Delete a file below a path alias.

Param ​

path

Path alias or root path.

Param ​

filename

File name.

Implementation of ​

ts
FS.file_delete

file_length ​

ts
file_length: Mock<(path: string) => -1 | 0>;

Get file length.

Param ​

path

File path.

Returns ​

File length in bytes, or engine error value.

Implementation of ​

ts
FS.file_length

file_list_open ​

ts
file_list_open: Mock<() => MockFileSystemList>;

Open a file list below a path alias and folder.

Param ​

alias

Filesystem path alias.

Param ​

folder

Folder inside the alias.

Param ​

flags

Listing flags.

Returns ​

File list.

Implementation of ​

ts
FS.file_list_open

file_list_open_ex ​

ts
file_list_open_ex: Mock<() => MockFileSystemList>;

Open a sortable filtered file list.

Remarks ​

Forces the path to be rescanned before collecting matching entries.

Param ​

path

Path or path alias.

Param ​

flags

Listing flags.

Param ​

mask

File mask.

Returns ​

Sortable file list.

Implementation of ​

ts
FS.file_list_open_ex

file_rename ​

ts
file_rename: Mock<() => void>;

Rename or move a file.

Param ​

path

Source file path.

Param ​

destination

Destination file path.

Param ​

overwrite

Whether an existing destination may be overwritten.

Implementation of ​

ts
FS.file_rename

get_file_age ​

ts
get_file_age: Mock<() => number>;

Get file modification timestamp.

Param ​

path

File path.

Returns ​

Modification timestamp.

Implementation of ​

ts
FS.get_file_age

get_file_age_str ​

ts
get_file_age_str: Mock<() => number>;

Get file modification timestamp as packed display value.

Param ​

path

File path.

Returns ​

Modification timestamp value.

Implementation of ​

ts
FS.get_file_age_str

get_path ​

ts
get_path: Mock<(alias: string) => {
  m_Add: string;
  m_DefExt: string;
  m_FilterCaption: string;
  m_Path: string;
  m_Root: string;
}>;

Get native path descriptor for an alias.

Remarks ​

Native code asserts when the alias is missing. Use FS.path_exist before calling when the alias is optional.

Param ​

alias

Filesystem path alias.

Returns ​

Native filesystem path descriptor.

Implementation of ​

ts
FS.get_path

mocks ​

ts
mocks: Record<string, any>;

path_exist ​

ts
path_exist: Mock<(path: string) => boolean>;

Check whether a path alias exists.

Param ​

path

Path alias.

Returns ​

Whether the path exists.

Implementation of ​

ts
FS.path_exist

paths ​

ts
paths: Record<string, string>;

permissiveRoots ​

ts
permissiveRoots: Set<string>;

Roots whose files are treated as existing unless a specific path is mocked otherwise.


r_close ​

ts
r_close: Mock<UnknownFunction>;

Close a binary reader.

Param ​

reader

Reader returned by r_open.

Implementation of ​

ts
FS.r_close

r_open ​

ts
r_open: MockedFunction<{
  (path: string): reader;
  (alias: string, path: string): reader;
}>;

Open a binary reader.

Param ​

path

File path.

Returns ​

Binary reader.

Implementation of ​

ts
FS.r_open

rescan_path ​

ts
rescan_path: Mock<UnknownFunction>;

Rescan a path alias.

Since ​

OpenXRay 2015-07-07, 6e703b4c

Remarks ​

Marks the alias as needing a rescan. The next filesystem check refreshes cached entries.

Param ​

path

Path alias.

Implementation of ​

ts
FS.rescan_path

update_path ​

ts
update_path: Mock<(base: string, part: string) => string>;

Resolve path alias and suffix into a real path.

Remarks ​

Non-Windows builds normalize path separators before returning the string.

Param ​

alias

Filesystem path alias.

Param ​

add

Relative path to append.

Returns ​

Resolved path.

Implementation of ​

ts
FS.update_path

w_close ​

ts
w_close: Mock<UnknownFunction>;

Close a binary writer.

Param ​

writer

Writer returned by w_open.

Implementation of ​

ts
FS.w_close

w_open ​

ts
w_open: Mock<() => {
}>;

Open a binary writer below a path alias.

Remarks ​

Can return null when native writer setup fails.

Param ​

path

Filesystem path alias.

Param ​

filename

Relative file path.

Returns ​

Binary writer, or null.

Implementation of ​

ts
FS.w_open

FS_ClampExt ​

ts
readonly static FS_ClampExt: 4;

Clamp listed paths by extension.


FS_ListFiles ​

ts
readonly static FS_ListFiles: 1;

List files.


FS_ListFolders ​

ts
readonly static FS_ListFolders: 2;

List folders.


FS_RootOnly ​

ts
readonly static FS_RootOnly: 8;

Do not recurse into subfolders.


FS_sort_by_modif_down ​

ts
readonly static FS_sort_by_modif_down: 5;

Sort by modification time, newest first.


FS_sort_by_modif_up ​

ts
readonly static FS_sort_by_modif_up: 4;

Sort by modification time, oldest first.


FS_sort_by_name_down ​

ts
readonly static FS_sort_by_name_down: 1;

Sort by name descending.


FS_sort_by_name_up ​

ts
readonly static FS_sort_by_name_up: 0;

Sort by name ascending.


FS_sort_by_size_down ​

ts
readonly static FS_sort_by_size_down: 3;

Sort by size descending.


FS_sort_by_size_up ​

ts
readonly static FS_sort_by_size_up: 2;

Sort by size ascending.


FSType_Any ​

ts
readonly static FSType_Any: 3;

Search virtual and external files.

Since ​

OpenXRay 2014-11-02, 827c9f58


FSType_External ​

ts
readonly static FSType_External: 2;

Search external files only.

Since ​

OpenXRay 2014-11-02, 827c9f58


FSType_Virtual ​

ts
readonly static FSType_Virtual: 1;

Search virtual registered files only.

Since ​

OpenXRay 2014-11-02, 827c9f58


MOCKS ​

ts
static MOCKS: Record<string, Record<string, boolean>>;