feat(services/opfs): add read, write, and stat support#7361
Open
jccampagne wants to merge 2 commits intoapache:mainfrom
Open
feat(services/opfs): add read, write, and stat support#7361jccampagne wants to merge 2 commits intoapache:mainfrom
jccampagne wants to merge 2 commits intoapache:mainfrom
Conversation
Implement core OPFS file operations on top of the existing skeleton: - Reader with byte range support via Blob.slice - Writer using FileSystemWritableFileStream with WriteParams - Stat returning content length and last modified time - Proper error mapping from DomException to OpenDAL ErrorKind - Root directory support with path normalization - Nested directory navigation with optional create This is a subset of the full OPFS implementation (wip_opfs_3), focusing on read/write before adding list and delete.
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.
Which issue does this PR close?
This is for OPFS backend: see #5799
Rationale for this change
This is a follow from #7199
Specifically this comment: #7199 (comment)
This is a subset of the full OPFS implementation (wip_opfs_3), focusing on read/write before adding list and delete, to make the PR easier to review.
As I understand it, OPFS as 2 kinds of APIs:
FileSystemSyncAccessHandleto read and write, can only be used in workers;GetFile+FileSystemWritableFileStream, can be using in main JS thread and works, but less efficient.I decided to go for the async version as it suits my use case (for now), and it it the most generic use case and requires less setup to use (no workers).
I saw the
TwoWaystrait - that could be used later to implement the alternative using the synch version of OPFS.Using SendWrapper to make some struct Send and Sync.
Use of buffer consideration
I considered the comment (#7199 (comment)) about using a "buffer":
Buffering everything in memory for a single write at
close()would increase memory pressure, which is already limited in wasm32. Users who want that behaviour can do it themselves: accumulate data in a buffer, pass it to the OPFS service in one call, and close. Forcing the buffered approach in the service would remove this flexibility; currently users can choose between streaming writes and single-shot buffered writes.For performance, OPFS offers FileSystemSyncAccessHandle ( https://developer.mozilla.org/en-US/docs/Web/API/FileSystemSyncAccessHandle ) but it's only available in web workers.
A future addition could implement the Sync API for more performance (as suggested in the other PR)
What changes are included in this PR?
Implement core OPFS file operations on top of the existing skeleton:
Are there any user-facing changes?
Added write, read, stat.
Added edge
tests in core/edge/opfs_wasm32.AI Usage Statement
Yes, Gemini and Claude to navigate the codebase, documentation; and help with some code.