Expand description
File system abstraction layer. Currently supporting storage on the filesystem and the browser domain-associated local storage (Web Storage API).
Storage APIs abstracted:
- Rust std file I/O (fs::xxx)
- NodeJS file I/O (fs::read_file_sync)
- Browser local storage
By default, all I/O functions will use the name of the file as a key for localstorage. If you want to manually specify the localstorage key.
Structs§
- Buffer
- Binding to the Node.js
Buffertype, used when exchanging binary data with the JavaScript runtime. - DirEntry
- A single entry returned when listing the contents of a directory.
- Metadata
- File metadata such as timestamps and size, abstracted across the native and Node.js file system backends.
- Options
- Per-operation options for the file system abstraction, primarily used to override the key under which data is stored in browser local storage.
Traits§
- Normalize
Path - Normalizes path, dereferencing relative references
.and..and converting path separators to current platform separators. (detects platform natively or via NodeJS if operating in WASM32 environment) - ToPlatform
- Convert path separators to unix or to current platform. Detects platform natively or using NodeJS if operating under WASM32 environment. Since in WASM32 paths default to forward slashes, when running WASM32 in Windows paths needs to be converted back and forth for various path-related functions to work.
Functions§
- create_
dir_ all - Recursively creates the directory
dirand any missing parent directories. - create_
dir_ all_ sync - Synchronously recursively creates the directory
dirand any missing parent directories. - exists
- Check if a file exists
- exists_
sync - Check if a file exists
- exists_
with_ options - Returns whether the file at
filenameexists. - exists_
with_ options_ sync - Synchronously returns whether the file at
filenameexists. - local_
storage - Returns the browser’s domain-associated
localStorageobject, panicking if it is not available in the current environment. - normalize
- Normalizes path, dereferencing relative references
.and..and converting path separators to current platform separators. (detects platform natively or via NodeJS if operating in WASM32 environment). UsesToPlatformto perform path conversion. - read
- Read binary file contents to a
Vec<u8>. If using within the web browser environment, a local storage key with the name of the file will be used and the data is assumed to be hex-encoded. - read_
binary_ with_ options - Reads the entire contents of
filenameinto a byte vector. - read_
binary_ with_ options_ sync - Synchronously reads the entire contents of
filenameinto a byte vector. - read_
json - Read text file and deserialized it using
serde-json. - read_
json_ sync - Read text file and deserialized it using
serde-json. - read_
json_ with_ options - Read text file and deserialized it using
serde-json. - read_
json_ with_ options_ sync - Read text file and deserialized it using
serde-json. - read_
sync - Read binary file contents to a
Vec<u8>. If using within the web browser environment, a local storage key with the name of the file will be used and the data is assumed to be hex-encoded. - read_
to_ string - Read file contents to a string. If using within the web browser environment, a local storage key with the name of the file will be used.
- read_
to_ string_ sync - Read file contents to a string. If using within the web browser environment, a local storage key with the name of the file will be used.
- read_
to_ string_ with_ options - Reads the entire contents of
filenameinto a UTF-8 string. - read_
to_ string_ with_ options_ sync - Synchronously reads the entire contents of
filenameinto a UTF-8 string. - readdir
- Lists the entries in directory
path, optionally including fileMetadatafor each entry whenmetadataistrue. - remove
- Remove the file at the given path. If using within the web browser environment, a local storage key with the name of the file will be removed.
- remove_
sync - Remove the file at the given path. If using within the web browser environment, a local storage key with the name of the file will be removed.
- remove_
with_ options - Removes the file at
filename. - remove_
with_ options_ sync - Synchronously removes the file at
filename. - rename
- Renames or moves the file from
fromtoto. - rename_
sync - Synchronously renames or moves the file from
fromtoto. - resolve_
path - Parses the supplied path resolving
~/to the home directory. - write
- Write a
Vec<u8>to a binary file. If using within the web browser environment, a local storage key with the name of the file will be used and the data will be hex-encoded. - write_
binary_ with_ options - Writes the bytes in
datatofilename, replacing any existing contents. - write_
binary_ with_ options_ sync - Synchronously writes the bytes in
datatofilename, replacing any existing contents. - write_
json - Write a serializable value to a text file using
serde-json. - write_
json_ sync - Write a serializable value to a text file using
serde-json. - write_
json_ with_ options - Write a serializable value to a text file using
serde-json. - write_
json_ with_ options_ sync - Write a serializable value to a text file using
serde-json. - write_
string - Write a string to a text file. If using within the web browser environment, a local storage key with the name of the file will be used.
- write_
string_ sync - Write a string to a text file. If using within the web browser environment, a local storage key with the name of the file will be used.
- write_
string_ with_ options - Writes
texttofilename, replacing any existing contents. - write_
string_ with_ options_ sync - Synchronously writes
texttofilename, replacing any existing contents. - write_
sync - Write a
Vec<u8>to a binary file. If using within the web browser environment, a local storage key with the name of the file will be used and the data will be hex-encoded.