pub struct FileSystem { /* private fields */ }Expand description
Read and write files inside a running microVM.
let sbx = Sandbox::get("web")?;
sbx.fs().write_file("/app/main.py", b"print('hi')")?;
let out = sbx.fs().read_to_string("/app/out.json")?;
sbx.fs().upload("./src", "/app/src")?;
sbx.fs().download("/app/dist", "./dist", true)?;Implementations§
Source§impl FileSystem
impl FileSystem
Sourcepub fn write_file(&self, path: &str, data: &[u8]) -> Result<()>
pub fn write_file(&self, path: &str, data: &[u8]) -> Result<()>
Write data to path in the guest, creating parent directories.
Sourcepub fn read_to_string(&self, path: &str) -> Result<String>
pub fn read_to_string(&self, path: &str) -> Result<String>
Read path from the guest and decode it as UTF-8 (lossily).
Sourcepub fn upload(
&self,
local_path: impl AsRef<Path>,
remote_path: &str,
) -> Result<()>
pub fn upload( &self, local_path: impl AsRef<Path>, remote_path: &str, ) -> Result<()>
Copy a host file or directory into the guest. A directory’s contents
land in remote_path, so upload("./src", "/app/src") leaves the
guest’s /app/src holding what ./src holds.
Whether it recurses is decided by looking at local_path, so callers do
not have to say which kind of thing they are copying.
Sourcepub fn download(
&self,
remote_path: &str,
local_path: impl AsRef<Path>,
recursive: bool,
) -> Result<()>
pub fn download( &self, remote_path: &str, local_path: impl AsRef<Path>, recursive: bool, ) -> Result<()>
Copy a file or directory out of the guest onto the host. recursive
selects a directory; unlike upload it cannot be
detected here, because the path lives in the guest and answering would
cost an extra round trip.
Auto Trait Implementations§
impl Freeze for FileSystem
impl RefUnwindSafe for FileSystem
impl Send for FileSystem
impl Sync for FileSystem
impl Unpin for FileSystem
impl UnsafeUnpin for FileSystem
impl UnwindSafe for FileSystem
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more