@fkn/lib’s fs implements a common path-based subset of Node fs. @fkn/fs-polyfill packages it as a browser replacement for Node’s built-in fs: point a bundler’s fs and fs/promises aliases at it and code using the supported operations resolves to FKN storage.
// vite.config.ts - or any bundler's resolve aliases
exportdefault {
resolve: {
alias: {
fs: '@fkn/fs-polyfill',
'fs/promises': '@fkn/fs-polyfill/promises',
},
},
}
// unchanged Node-style code, now running in the browser on FKN storage
import fs from'fs'
import { mount } from'@fkn/fs-polyfill'
awaitmount() // hydrate the in-memory layer before sync reads
There is no synchronous disk in a browser, so the polyfill keeps an in-memory layer that synchronous calls read
and write instantly. mount() hydrates it from storage; a sync read before it resolves sees ENOENT. The
promise and callback forms await the mount internally. Writes flush back to storage on a debounce and on
tab-hide. flush() attempts pending local or hybrid backing writes but catches backing failures and still resolves. Cloud replication from the hybrid backing is best-effort and can finish later. Use cloud.fs for an awaited cloud write.
The common file operations - read, write, append, stat, readdir, mkdir, rm, rename - in sync, callback, and
promise forms. File descriptors (open / fd), streams (createReadStream), watch, and readdir’s
withFileTypes are not implemented yet. There is no symlink support either: lstat is aliased to stat, and
Stats.isSymbolicLink() always returns false.