File I/O
Spark provides a unified filesystem API for moving data between your local browser, the cloud storage at torchjs.org, and your background workers.

Remote Storage (torchjs.org)
Load model weights and datasets directly from the community hub.
spark.load()
Loads a file as an ArrayBuffer. Works with .pt, .safetensors, and raw binary data.
const weights = await spark.load('username/model/checkpoint.pt');
model.load_state_dict(torch.load(weights));spark.save()
Saves local data to your account on torchjs.org.
const buffer = torch.save(model.state_dict());
await spark.save('my-user/my-model/latest.pt', buffer);Datasets
The spark.dataset() method is optimized for loading large training sets with a torch.json manifest.
const mnist = await spark.dataset('torchjs/mnist');
// Access images and labels via mnist.train and mnist.testLocal Storage (IndexedDB)
For persistent storage that doesn't require an internet connection, use the Local family of methods.
| Method | Storage Target |
|---|---|
| saveLocal(key, data) | Browser IndexedDB |
| loadLocal(key) | Browser IndexedDB |
| clearLocal() | Wipe all local torch data |