Guide

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)

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?)

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?)

Restore a snapshot created by snapshot().

await restoreSnapshot(storage, { "foo:bar": "baz" }, "/etc2");