FileStorageResolver
The FileStorageResolver class provides a flexible way to configure and switch between different FileStorage adapters at runtime.
Initial configuration
To begin using the IFileStorageFactory, You will need to register all required adapters during initialization.
import { FileStorageResolver } from "eridu-tech/FileStorage";
import { MemoryFileStorageAdapter } from "eridu-tech/FileStorage/memory-FileStorage-adapter";
import { FsFileStorageAdapter } from "eridu-tech/FileStorage/fs-FileStorage-adapter";
const fileStorageResolver = new FileStorageResolver({
adapters: {
memory: new MemoryFileStorageAdapter(),
fs: new FsFileStorageAdapter(),
},
// You can set an optional default adapter
defaultAdapter: "memory",
});
Usage
1. Using the default adapter
await fileStorageResolver.use().create("file.txt").add("Text file content");
danger
Note that if you dont set a default adapter, an error will be thrown.
2. Specifying an adapter explicitly
await fileStorageResolver.use("fs").create("file.txt").add("Text file content");
danger
Note that if you specify a non-existent adapter, an error will be thrown.
3. Overriding default settings
await fileStorageResolver
.setNamespace(new Namespace("@my-namespace"))
.use("fs")
.create("file.txt")
.add("Text file content");
info
Note that the FileStorageResolver is immutable, meaning any configuration override returns a new instance rather than modifying the existing one.
Further information
For further information refer to eridu-tech/FileStorage API docs.