feat: WritableFS, LocalFS, MemFS, and fs.FS-backed FileSystemLoader#2
Merged
Conversation
…emLoader Adds portable filesystem abstractions for template storage: WritableFS interface: - Extends fs.FS with WriteFile, MkdirAll, Remove, Rename - Enables template storage on local disk, S3, IndexedDB (WASM), in-memory LocalFS: - WritableFS backed by local OS filesystem - All paths relative to a root directory MemFS: - WritableFS backed by in-memory map - Full fs.FS compliance (Open, ReadFile, ReadDir, Stat with directory inference) - Write isolation (copies on write to prevent aliasing) - Useful for testing and WASM environments FileSystemLoader fs.FS support: - New FileSystems []fs.FS field: FileSystems[i] backs Folders[i] - nil entry = OS filesystem (backward compatible) - Existing code using only Folders works unchanged 19 new tests covering: - LocalFS: write/read roundtrip, mkdir, remove, rename, readdir - MemFS: write/read, open, remove, rename, readdir, stat, isolation, dir inference - FileSystemLoader: MemFS-backed loading, mixed FS+OS, backward compat, not-found
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Adds portable filesystem abstractions to Templar, enabling template storage beyond the local disk (S3, IndexedDB/WASM, in-memory for tests).
New types
WritableFSfs.FS+WriteFile/MkdirAll/Remove/RenameLocalFSWritableFSbacked by local OS filesystem (relative to root dir)MemFSWritableFSbacked by in-memory map (testing, WASM)FileSystemLoader enhancement
New
FileSystems []fs.FSfield whereFileSystems[i]backsFolders[i]:When
FileSystems[i]is nil (or the slice is shorter), falls back to OS filesystem — fully backward compatible.Motivation
Slyds (presentation toolkit) needs to store decks on various backends. Rather than invent a separate filesystem abstraction, we're adding it to Templar where the template loader can use it directly. This benefits any Templar user who wants templates from non-OS sources.
Tests
19 new tests covering LocalFS, MemFS (including write isolation, directory inference), FileSystemLoader with MemFS, mixed FS+OS, backward compatibility.
All existing tests pass unchanged.