nx.js
NamespacesSwitchClasses

FileSystem

Properties

PropertyTypeDescription
urlnull | URLA URL instance that points to the root of the filesystem mount. You should use this to create file path references within the filesystem mount. Example const dataUrl = new URL('data.json', fileSystem.url);

Methods

freeSpace()

freeSpace(): bigint

The amount of free space available on the filesystem, in bytes.

Returns

bigint


mount()

mount(name): URL

Mounts the FileSystem such that filesystem operations may be used.

Parameters

ParameterTypeDescription
namestringThe name of the mount for filesystem paths. By default, a random name is generated. Should not exceed 31 characters, and should not have a trailing colon.

Returns

URL


totalSpace()

totalSpace(): bigint

The total amount of space available on the filesystem, in bytes.

Returns

bigint


openBis()

static openBis(id): FileSystem

Opens a file system partition specified by its BisPartitionId.

Parameters

ParameterTypeDescription
idnumberThe BisPartitionId of the partition to open.

Returns

FileSystem

Example

import { BisPartitionId } from '@nx.js/constants';
 
// Open and mount the "User" partition
const fs = Switch.FileSystem.openBis(BisPartitionId.User);
const url = fs.mount();
 
// Read the file entries at the root of the partition
console.log(Switch.readDirSync(url));

openSdmc()

static openSdmc(): FileSystem

Opens a file system partition for the SD card.

Note that the SD card is automatically mounted under the sdmc: protocol, so your application will not need to call this function under most circumstances. However, it is useful for querying metatdata about the SD card, such as the amount of free space available.

Returns

FileSystem

Example

const fs = Switch.FileSystem.openSdmc();
console.log(fs.freeSpace());
console.log(fs.totalSpace());

openWithId()

static openWithId(titleId, type, path?): FileSystem

Opens a file system partition for the application with the specified title ID. The file system type is specified by the FsFileSystemType parameter.

Parameters

ParameterTypeDescription
titleIdbigintThe title ID of the file system to open.
typenumberThe FsFileSystemType of the file system to open.
path?stringThe base path of the file system to open. Defaults to /.

Returns

FileSystem

Example

import { FsFileSystemType } from '@nx.js/constants';
 
// Open and mount the "User" partition
const fs = Switch.FileSystem.openWithId(
  0x0100000000001000n,
  FsFileSystemType.ContentMeta,
);
const url = fs.mount();
 
// Read the file entries at the root of the file system
console.log(Switch.readDirSync(url));

On this page