mirror of
https://github.com/unjs/unstorage.git
synced 2026-01-25 16:43:47 +00:00
1016 B
1016 B
Extra Utilities
Unstorage exposes several utilities. You can individually import them and add only needed bytes to your bundle.
Namespace
Create a namespaced instance of main storage. All operations are virtually prefixed. Useful to create shorcuts and limit access.
prefixStorage(storage, prefix){lang=ts}
import { createStorage, prefixStorage } from "unstorage";
const storage = createStorage();
const assetsStorage = prefixStorage(storage, "assets");
// Same as storage.setItem('assets:x', 'hello!')
await assetsStorage.setItem("x", "hello!");
Snapshots
snapshot(storage, base?){lang=ts}
Take a snapshot from all keys in specified base into a plain javascript object (string: string). Base is removed from keys.
import { snapshot } from "unstorage";
const data = await snapshot(storage, "/etc");
restoreSnapshot(storage, data, base?){lang=ts}
Restore a snapshot created by snapshot().
await restoreSnapshot(storage, { "foo:bar": "baz" }, "/etc2");