Crate sos_vfs

source ·
Expand description

Virtual file system.

The API is designed to match the tokio::fs module which in turn is based on std::fs so the API should be familiar.

The default operating system VFS re-exports the tokio::fs module providing access to the operating system’s file system.

Using the memory VFS allows us to compile and target the wasm32-unknown-unknown platform with minimal changes to the code.

The memory file system is enabled by default for wasm32-unknown-unknown or if the mem-fs feature is enabled.

Memory VFS Caveats

Relative paths are resolved from the root of the file system.

Avoid using the PathBuf functions exists(), metadata(), is_dir(), is_file() etc as they will be incorrect when using a virtual file system. Instead use the vfs::metadata() and vfs::try_exists() asynchronous functions.

The SystemTime type is not available on wasm32-unknown-unknwown so Metadata does not support created(), accessed() and modified() for that target.

Memory VFS Unsupported

This functionality is not supported yet but we hope to implement in the future.

The readonly flag on permissions is not supported yet.

Created, accessed and modified times are not set yet for non-webassembly targets that support SystemTime.

Symbolic links are not supported yet which means the hard_link(), symlink(), symlink_metadata(), symlink_file() and symlink_dir() functions are not available.

Structs

  • A builder for creating directories in various manners.
  • Entries returned by the ReadDir stream.
  • A reference to an open file on the filesystem.
  • Options and flags which can be used to configure how a file is opened.
  • Reads the entries in a directory.

Functions

  • Returns the canonical, absolute form of a path with all intermediate components normalized and symbolic links resolved.
  • Copies the contents of one file to another. This function will also copy the permission bits of the original file to the destination file. This function will overwrite the contents of to.
  • Creates a new, empty directory at the provided path.
  • Recursively creates a directory and all of its parent components if they are missing.
  • Creates a new hard link on the filesystem.
  • Given a path, queries the file system to get information about a file, directory, etc.
  • Reads the entire contents of a file into a bytes vector.
  • Returns a stream over the entries within a directory.
  • Reads a symbolic link, returning the file that the link points to.
  • Creates a future which will open a file for reading and read the entire contents into a string and return said string.
  • Removes an existing, empty directory.
  • Removes a directory at this path, after removing all its contents. Use carefully!
  • Removes a file from the filesystem.
  • Renames a file or directory to a new name, replacing the original file if to already exists.
  • Changes the permissions found on a file or a directory.
  • Creates a new symbolic link on the filesystem.
  • Queries the file system metadata for a path.
  • Returns Ok(true) if the path points at an existing entity.
  • Creates a future that will open a file for writing and write the entire contents of contents to it.