Skip to main content

FileSystem

Struct FileSystem 

Source
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

Source

pub fn write_file(&self, path: &str, data: &[u8]) -> Result<()>

Write data to path in the guest, creating parent directories.

Source

pub fn read_file(&self, path: &str) -> Result<Vec<u8>>

Read path from the guest as bytes.

Source

pub fn read_to_string(&self, path: &str) -> Result<String>

Read path from the guest and decode it as UTF-8 (lossily).

Source

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.

Source

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§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<ST, DT> CastableFrom<ST, Initialized, Initialized> for DT
where ST: ?Sized, DT: ?Sized,

Source§

impl<ST, DT> CastableFrom<ST, Uninit, Uninit> for DT
where ST: ?Sized, DT: ?Sized,

Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> Read<Exclusive, BecauseExclusive> for T
where T: ?Sized,

Source§

impl<T> Same for T

Source§

type Output = T

Should always be Self
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
Source§

impl<V, T> VZip<V> for T
where V: MultiLane<T>,

Source§

fn vzip(self) -> V