Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

wasm: Fix operation not supported on std::fs. Closes #115 #166

Merged
merged 21 commits into from
May 29, 2019
Merged

Conversation

iceiix
Copy link
Owner

@iceiix iceiix commented May 23, 2019

Implementing a minimal web-based std::fs replacement for #115 wasm broken: panicked at 'called Result::unwrap() on an Err value: Custom { kind: Other, error: StringError("operation not supported on wasm yet") }

@iceiix
Copy link
Owner Author

iceiix commented May 23, 2019

Emscripten for reference: https://github.com/emscripten-core/emscripten/blob/incoming/src/library_fs.js

https://emscripten.org/docs/api_reference/Filesystem-API.html supports MEMFS (in-memory), NODEFS (node.js only), and IDBFS (browser only).

IDB = IndexedDB, https://www.w3.org/TR/IndexedDB/, seems to be the best. Supports storing Uint8Array binary keys, in contrast to localStorage https://developer.mozilla.org/en-US/docs/Web/API/Window/localStorage which only allows string values.

Is there an existing crate for IndexedDB in Rust? https://crates.io/crates/indexeddb last modified 5 months ago, 0.1.0 disclaimer "very early stages". https://docs.rs/stdweb/0.4.17/stdweb/ seems not to support it? There is an open merge request: koute/stdweb#297 from January, not merged with some pending feedback.

Emscripten's IndexedDB filesystem:

https://github.com/emscripten-core/emscripten/blob/incoming/src/IDBStore.js
https://github.com/emscripten-core/emscripten/blob/incoming/src/library_idbstore.js
https://github.com/emscripten-core/emscripten/blob/incoming/src/library_idbfs.js

Mozilla documentation: https://developer.mozilla.org/en-US/docs/Web/API/IndexedDB_API https://developer.mozilla.org/en-US/docs/Web/API/IndexedDB_API/Using_IndexedDB

@iceiix
Copy link
Owner Author

iceiix commented May 24, 2019

Moved to a separate module, replaced std::fs everywhere, so far so good. Barely implemented any of the API, but that's all I'm using. However, it doesn't persist the data anywhere, yet. Would be used for configuration (conf.cfg), server list (servers.json), packet debugging (last-packet), resources (although it is disabled on wasm32 for now), and skins (ditto).

Next up, use stdweb indexeddb branch (koute/stdweb#342) to provide a persistence backend. Start out simple first, but this could be useful for others to publish as a new crate.

@iceiix
Copy link
Owner Author

iceiix commented May 25, 2019

As koute/stdweb#342 is still in review may change, and the Indexed DB API is quite complex, hacked up a quick and dirty Local Storage backend for now. Since it only stores strings, encoded the bytes as hex. This works, conf.cfg is written:

Screen Shot 2019-05-24 at 6 29 24 PM

and decodes correctly, albeit ugly.

@iceiix iceiix merged commit 836ab9f into master May 29, 2019
@iceiix iceiix deleted the webfs branch May 29, 2019 15:22
iceiix added a commit that referenced this pull request Feb 1, 2020
* Add new web-based std::fs replacement, localstoragefs:

https://github.com/iceiix/localstoragefs

* Add std_or_web to switch between std::fs (native) or localstoragefs (web)

* Update www readme for new missing glutin/winit links, opens issue #171
iceiix added a commit that referenced this pull request Feb 1, 2020
* Add new web-based std::fs replacement, localstoragefs:

https://github.com/iceiix/localstoragefs

* Add std_or_web to switch between std::fs (native) or localstoragefs (web)

* Update www readme for new missing glutin/winit links, opens issue #171
iceiix added a commit that referenced this pull request Feb 1, 2020
* Add new web-based std::fs replacement, localstoragefs:

https://github.com/iceiix/localstoragefs

* Add std_or_web to switch between std::fs (native) or localstoragefs (web)

* Update www readme for new missing glutin/winit links, opens issue #171
iceiix added a commit that referenced this pull request Feb 2, 2020
* Add new web-based std::fs replacement, localstoragefs:

https://github.com/iceiix/localstoragefs

* Add std_or_web to switch between std::fs (native) or localstoragefs (web)

* Update www readme for new missing glutin/winit links, opens issue #171
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant