DOC Add a FAQ entry for async filesystem usage (#3222)

Co-authored-by: Roman Yurchak <rth.yurchak@gmail.com>
This commit is contained in:
Gyeongjae Choi 2022-11-04 11:04:35 +09:00 committed by GitHub
parent 950bc8b182
commit 3a7e1ccbd4
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 13 additions and 1 deletions

View File

@ -51,7 +51,8 @@ For security reasons JavaScript in the browser is not allowed to load local data
You will run into Network Errors, due to the [Same Origin Policy](https://en.wikipedia.org/wiki/Same-origin_policy).
There is a
[File System API](https://wicg.github.io/file-system-access/) supported in Chrome
but not in Firefox or Safari.
but not in Firefox or Safari. See {ref}`nativefs-api` for experimental local file system
support.
For development purposes, you can serve your files with a
[web server](https://developer.mozilla.org/en-US/docs/Learn/Common_questions/set_up_a_local_testing_server).
@ -409,3 +410,12 @@ importlib.invalidate_caches() # Make sure Python notices the new .py file
from mymodule import hello
hello()
```
## Why changes made to IndexedDB don't persist?
Unlike other filesystems, IndexedDB (pyodide.FS.filesystem.IDBFS) is an asynchronous filesystem.
This is because browsers offer only asynchronous interfaces for IndexedDB.
So in order to persist changes, you have to call
[`pyodide.FS.syncfs()`](https://emscripten.org/docs/api_reference/Filesystem-API.html#FS.syncfs).
See [Emscripten File System API](https://emscripten.org/docs/api_reference/Filesystem-API.html#persistent-data)
for more details.

View File

@ -58,6 +58,8 @@ pyodide.runPython("import os; print(os.listdir('/mnt'))");
// ==> The list of files in the Node working directory
```
(nativefs-api)=
# (Experimental) Using native file system in the browser
You can access native file system from the browser using the