nx.js
NamespacesSwitchClasses

SaveData

Represents a "save data store".

Properties

PropertyModifierTypeDescription
applicationIdreadonlybigintThe title (program) ID of the application that owns this save data. 0n for system saves not tied to an application.
idreadonlybigintUnique identifier for this save data store. Assigned by the system when the save data is created.
indexreadonlynumberIndex used to disambiguate multiple save data stores that share the same applicationId / uid / type. Typically 0 unless the application uses indexed save data.
rankreadonlynumberSave data rank — 0 for the primary save data, non-zero for secondary (BCAT-style) ranks. Most application saves are rank 0.
sizereadonlybigintTotal size of the save data store, in bytes.
spaceIdreadonlynumberThe save data space (storage location) that this save data lives in. Compare against members of FsSaveDataSpaceId (e.g. User = 1, System = 0, SdUser = 4).
systemIdreadonlybigintThe system data ID, used for system-type save data. 0n for application save data.
typereadonlynumberThe kind of save data this represents (per-user account save, system save, BCAT, device, temporary, cache, etc.). Compare against members of FsSaveDataType.
uidreadonlyProfileUidThe user account that this save data is associated with, as a tuple of two bigints ([lo, hi]) matching the layout of Profile.uid. Set to [0n, 0n] for save data not tied to a user (e.g. system or device saves).
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.

Warning

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. Should not exceed 31 characters, and should not 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

On this page