SaveData
Represents a "save data store".
Properties
| Property | Modifier | Type | Description |
|---|---|---|---|
applicationId | readonly | bigint | The title (program) ID of the application that owns this save data. 0n for system saves not tied to an application. |
id | readonly | bigint | Unique identifier for this save data store. Assigned by the system when the save data is created. |
index | readonly | number | Index used to disambiguate multiple save data stores that share the same applicationId / uid / type. Typically 0 unless the application uses indexed save data. |
rank | readonly | number | Save data rank — 0 for the primary save data, non-zero for secondary (BCAT-style) ranks. Most application saves are rank 0. |
size | readonly | bigint | Total size of the save data store, in bytes. |
spaceId | readonly | number | The save data space (storage location) that this save data lives in. Compare against members of FsSaveDataSpaceId (e.g. User = 1, System = 0, SdUser = 4). |
systemId | readonly | bigint | The system data ID, used for system-type save data. 0n for application save data. |
type | readonly | number | The kind of save data this represents (per-user account save, system save, BCAT, device, temporary, cache, etc.). Compare against members of FsSaveDataType. |
uid | readonly | ProfileUid | The 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). |
url | public | null | URL | A 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 diskdelete()
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
| Parameter | Type | Description |
|---|---|---|
dataSize | bigint | |
journalSize | bigint |
Returns
void
freeSpace()
freeSpace(): bigint
Returns
bigint
mount()
mount(name): URL
Mounts the save data such that filesystem operations may be used.
Parameters
| Parameter | Type | Description |
|---|---|---|
name | string | The 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
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]()
Returns
Generator<SaveData, void, unknown>
createSync()
createSync(init)
static createSync(init): SaveData
Parameters
| Parameter | Type |
|---|---|
init | SaveDataCreationInfoBase |
Returns
createSync(init, nacp)
static createSync(init, nacp): SaveData
Parameters
| Parameter | Type |
|---|---|
init | SaveDataCreationInfoWithNacp |
nacp | ArrayBuffer |