A robust abstraction layer for the Origin Private File System (OPFS) API, allowing seamless file operations across all browsers. This package resolves Safari's limitations with OPFS, providing a consistent experience.
To learn more, watch this quick video:
Install reold-opfs using npm:
npm install gist:86a64385efd4ec10674f4744da655505This package provides a simple API for interacting with OPFS using a worker thread. Use the useOPFS object for file operations. Here is how you can set up and use it:
import fsWorker from "reold-opfs/opfsWorker.ts?worker";
import { useOPFS } from "reold-opfs/opfs";
// Set the worker instance
useOPFS.setWorker(new fsWorker());
// Optionally enable debug mode
useOPFS.setDebug(true);await useOPFS.write("hello.txt", "Hello, world!");
console.info("File written successfully");Sets the intermediary worker that performs OPFS operations.
workerInstance: An instance of theopfsWorkerto handle file system operations.
Enables or disables debug messages for communication between the main and worker threads.
showDebug: A boolean value to toggle debug messages.
Writes content to a file in OPFS.
path: The path to the file in OPFS (e.g.,"documents/example.txt").content: The content to write to the file, which can be a string or a Blob.- Returns: A promise that resolves when the write operation is complete.
If you have any feedback, feel free to reach out to me via my socials or email. ✨
Originally designed for Cartier Manager.
