nx.js
NamespacesSwitchClasses

SaveData

Represents a "save data store".

Properties

PropertyModifierTypeDescription
applicationIdreadonlybigint-
idreadonlybigint-
indexreadonlynumber-
rankreadonlynumber-
sizereadonlybigint-
spaceIdreadonlynumber-
systemIdreadonlybigint-
typereadonlynumber-
uidreadonlyProfileUid-
urlpublicnull | 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', saveData.url);

Methods

commit()

commit(): void

Commits to the disk any write operations that have occurred on this filesystem mount since the previous commit.

Failure to call this function after writes will cause the data to be lost after the application exits.

Returns

void

Example

const saveStateUrl = new URL('state', saveData.url);
Switch.writeFileSync(saveStateUrl, 'my application state...');
 
saveData.commit(); // Write operation is persisted to the disk

delete()

delete(): void

Deletes the save data store.

Caution

This is a destructive operation! Use caution when using this function to avoid accidental data loss, such as prompting the user to confirm the deletion.

Returns

void


extend()

extend(dataSize, journalSize): void

Grows a save data store to the requested dataSize and journalSize.

Parameters

ParameterTypeDescription
dataSizebigint
journalSizebigint

Returns

void


freeSpace()

freeSpace(): bigint

Returns

bigint


mount()

mount(name): URL

Mounts the save data such that filesystem operations may be used.

Parameters

ParameterTypeDescription
namestringThe name of the mount for filesystem paths. By default, a random name is generated. Shouldn't exceed 31 characters, and shouldn't have a trailing colon.

Returns

URL


totalSpace()

totalSpace(): bigint

Returns

bigint


unmount()

unmount(): void

Unmounts the filesystem mount. Any filesytem operations attempting to use the mount path in the future will throw an error.

Returns

void

Example

Switch.readDirSync(saveData.url); // OK
 
saveData.unmount();
 
Switch.readDirSync(saveData.url); // ERROR THROWN!

[iterator]()

static [iterator](): Generator<SaveData, void, unknown>

Returns

Generator<SaveData, void, unknown>


createSync()

createSync(init)

static createSync(init): SaveData

Parameters
ParameterType
initSaveDataCreationInfoBase
Returns

SaveData

createSync(init, nacp)

static createSync(init, nacp): SaveData

Parameters
Returns

SaveData


filter()

static filter(filter): Generator<SaveData, void, unknown>

Parameters

ParameterType
filterSaveDataFilter

Returns

Generator<SaveData, void, unknown>


find()

static find(filter): undefined | SaveData

Parameters

ParameterType
filterSaveDataFilter

Returns

undefined | SaveData

On this page