Skip to content

Return values (response types)

All Virtual File System (VFS) methods return one of the following response types. Each type provides a consistent way to check for success and retrieve results or error information.

TypeDescription
respBaseBase type: success/failure, error message
respSizeSize (in bytes) of a file or directory
respStatMetadata for a single file or directory
respDirDirectory listing (array of items)
respReadStringFile read result as string or hex
respReadBytesFile read result as byte array

TIP

Always check the result's Ok() method before using any returned data. If Ok() returns false, use ErrorMsg() to retrieve a human-readable error message.

respBase

This is the ancestor to all possible VFS return values. Every other return value inherits from this one and therefore has the same methods (in addition to those of the derived class).

ts
interface respBase {
  function Ok(): boolean;      // true if the method succeeded, false otherwise
  function ErrorMsg(): string; // if (!Ok()) this method returns a human-readable error message
}

IMPORTANT

All other return value types are derived from respBase, so all of them have the Ok() and ErrorMsg() methods even when not explicitly documented.

respSize

Returned by methods like TreeSize(), provides the size (in bytes) of a single file or directory.

ts
interface respSize {
  respBase;
  function Size(): number; // originally a 64-bit integer in the host process
}

respStat

Returned by methods like Stat() or Lstat(), provides metadata for a single file or directory.

ts
interface respStat {
  respBase;
  function Info(): DirListItem; // exactly 1 (one) DirListItem
}

Read more about the structure of the DirListItem object.

respDir

Returned by the ReadDir() method, provides a directory listing as an array of items.

ts
interface respDir {
  respBase;
  function Infos(): []DirListItem; // array of DirListItem
}

Read more about the structure of the DirListItem object.

respReadString

Returned when reading a file as text or as a hexadecimal string.

ts
interface respReadString {
  respBase;
  function Data(): string;
}

respReadBytes

Returned when reading a file as an array of bytes.

ts
interface respReadBytes {
  respBase;
  function Data(): Uint8Array; // array of unsigned 8-bit integers (bytes)
}

Example: Checking for Success and Handling Errors

ts
var stat = vfs.Stat("/some/file.txt");
if (stat.Ok()) {
  var info = stat.Info();
  // use info here
} else {
  Log("Stat failed: " + stat.ErrorMsg());
}