diff --git a/vm/src/vm/runners/cairo_pie.rs b/vm/src/vm/runners/cairo_pie.rs index 3f39179acb..bf76f7831f 100644 --- a/vm/src/vm/runners/cairo_pie.rs +++ b/vm/src/vm/runners/cairo_pie.rs @@ -171,7 +171,7 @@ impl CairoPie { pub fn from_zip_archive( mut zip: zip::ZipArchive, - ) -> Result { + ) -> Result { let metadata: CairoPieMetadata = Self::parse_zip_file(zip.by_name("metadata.json")?)?; let execution_resources: ExecutionResources = Self::parse_zip_file(zip.by_name("execution_resources.json")?)?; @@ -189,7 +189,7 @@ impl CairoPie { }; let memory = Self::read_memory_file(zip.by_name("memory.bin")?, addr_size, felt_bytes)?; - Ok(CairoPie { + Ok(Self { metadata, memory, execution_resources, @@ -198,13 +198,22 @@ impl CairoPie { }) } + /// Builds a CairoPie object from an array of bytes. + #[cfg(feature = "std")] + pub fn from_bytes(bytes: &[u8]) -> Result { + let reader = std::io::Cursor::new(bytes); + let zip_archive = zip::ZipArchive::new(reader)?; + + Self::from_zip_archive(zip_archive) + } + /// Builds a CairoPie object from a ZIP archive. #[cfg(feature = "std")] - pub fn from_file(path: &Path) -> Result { + pub fn from_file(path: &Path) -> Result { let file = std::fs::File::open(path)?; let zip = zip::ZipArchive::new(file)?; - CairoPie::from_zip_archive(zip) + Self::from_zip_archive(zip) } }