In-memory persistence
MemoryAssetSource keeps assets in one source instance. It is useful for tests and in-process workflows that do not need filesystem storage.
new MemoryAssetSource(
files?: Iterable<readonly [string, Uint8Array]>
)import { MemoryAssetSource } from "@jolly-pixel/asset-source";
const source = new MemoryAssetSource([
["textures/grass.png", new Uint8Array([1, 2, 3])]
]);The constructor, write and writeIfAbsent copy their input bytes. read also returns a copy, so changing a supplied or returned array does not change the stored asset. Each source has its own data.
Folders are kept as a set of paths beside the files: write adds the folders of its path and createFolder adds one with its parents.
The source implements the shared AssetSource storage contract. isIgnored matches the .jollypixel/ state directory only, and the source does not provide watch.
🌍 Browser compatibility
The root entry exports the AssetSource contract, MemoryAssetSource, IndexedDbAssetSource, the path and JSON utilities, and the constants. It imports no Node.js builtin, so a browser bundle can use it. The filesystem source and the HTTP handler live in @jolly-pixel/asset-source/node.