Buckets:
| /* | |
| * Copyright 2014 The Emscripten Authors. All rights reserved. | |
| * Emscripten is available under two separate licenses, the MIT license and the | |
| * University of Illinois/NCSA Open Source License. Both these licenses can be | |
| * found in the LICENSE file. | |
| */ | |
| int main() { | |
| EM_ASM( | |
| var ex; | |
| var contents; | |
| // write a file that should be unaffected by this process | |
| FS.writeFile('/safe.txt', 'abc'); | |
| // mount it the first time | |
| FS.mkdir('/working'); | |
| FS.mount(MEMFS, {}, '/working'); | |
| FS.writeFile('/working/waka.txt', 'az'); | |
| // check the waka file | |
| contents = FS.readFile('/working/waka.txt', { encoding: 'utf8' }); | |
| assert(contents === 'az'); | |
| // the legacy API requires a mount directory to exist, while WasmFS will create the directory. | |
| try { | |
| FS.mount(MEMFS, {}, '/missing'); | |
| } catch (e) { | |
| ex = e; | |
| } | |
| assert(ex.name === 'ErrnoError' && ex.errno === 44); // ENOENT | |
| ex = null; | |
| // WasmFS will throw an error if a directory to mount to is not empty, while the legacy API will not. | |
| try { | |
| FS.mkdir("/test"); | |
| FS.writeFile("/test/hi.txt", "abc"); | |
| FS.mount(MEMFS, {}, '/test'); | |
| } catch (e) { | |
| ex = e; | |
| } | |
| assert(ex.name === 'ErrnoError' && ex.errno === 55); // ENOTEMPTY | |
| ex = null; | |
| // mount to an existing mountpoint | |
| try { | |
| FS.mount(MEMFS, {}, '/working'); | |
| } catch (e) { | |
| ex = e; | |
| } | |
| // WasmFS returns ENOTEMPTY instead of EBUSY in exchange for a simpler implementation. | |
| assert(ex.name === 'ErrnoError' && ex.errno === 55); // ENOTEMPTY | |
| assert(ex.name === 'ErrnoError' && ex.errno === 10); // EBUSY | |
| ex = null; | |
| // attempt to unmount a non-mountpoint directory inside a mountpoint | |
| FS.mkdir('/working/unmountable'); | |
| try { | |
| FS.unmount('/working/unmountable'); | |
| } catch (e) { | |
| ex = e; | |
| } | |
| assert(ex.name === 'ErrnoError' && ex.errno === 28); // EINVAL | |
| ex = null; | |
| // unmount | |
| FS.unmount('/working'); | |
| // unmount something that's not mounted | |
| try { | |
| FS.unmount('/working'); | |
| } catch (e) { | |
| ex = e; | |
| } | |
| // WasmFS will remove a directory on unmount, regardless of if a directory existed before. | |
| assert(ex.name === 'ErrnoError' && ex.errno === 44); // ENOENT | |
| assert(ex.name === 'ErrnoError' && ex.errno === 28); // EINVAL | |
| ex = null; | |
| // mount and unmount again | |
| FS.mount(MEMFS, {}, '/working'); | |
| FS.unmount('/working'); | |
| ex = null; | |
| // try to read the file from the old mount | |
| try { | |
| FS.readFile('/working/waka.txt', { encoding: 'utf8' }); | |
| } catch (e) { | |
| ex = e; | |
| } | |
| // WasmFS readFile aborts on failure, instead throwing an ErrnoError. | |
| assert(ex.name === 'ErrnoError' && ex.errno === 44); // ENOENT | |
| assert(ex); | |
| ex = null; | |
| // check the safe file | |
| contents = FS.readFile('/safe.txt', { encoding: 'utf8' }); | |
| assert(contents === 'abc'); | |
| // test JS_FILE backend | |
| FS.mount(JSFILEFS, {}, "/jsfile"); | |
| FS.writeFile("/jsfile/jsfile.txt", "a=1"); | |
| assert(FS.readFile("/jsfile/jsfile.txt", { encoding: 'utf8' }) === 'a=1'); | |
| FS.unmount("/jsfile"); | |
| // test ICASE backend | |
| FS.mount(ICASEFS, { backend: MEMFS }, "/icase"); | |
| FS.writeFile("/icase/IGNORE.txt", "a=1"); | |
| assert(FS.readFile("/icase/Ignore.txt", { encoding: 'utf8' }) === 'a=1'); | |
| assert(FS.readFile("/icase/ignore.TXT", { encoding: 'utf8' }) === 'a=1'); | |
| FS.unmount("/icase"); | |
| ); | |
| puts("success"); | |
| return 0; | |
| } | |
Xet Storage Details
- Size:
- 3.71 kB
- Xet hash:
- d560508147dd7113ce9739e52ec227093a0e557dbb11786553f70599902e1275
·
Xet efficiently stores files, intelligently splitting them into unique chunks and accelerating uploads and downloads. More info.