diff --git a/vm/src/vm/runners/cairo_pie.rs b/vm/src/vm/runners/cairo_pie.rs index caa35e91ee..e2f744a3b7 100644 --- a/vm/src/vm/runners/cairo_pie.rs +++ b/vm/src/vm/runners/cairo_pie.rs @@ -218,7 +218,7 @@ impl CairoPie { pub fn from_zip_archive( mut zip: zip::ZipArchive, - ) -> Result { + ) -> Result { let metadata: CairoPieMetadata = parse_zip_file(zip.by_name("metadata.json")?)?; let execution_resources: ExecutionResources = parse_zip_file(zip.by_name("execution_resources.json")?)?; @@ -235,7 +235,7 @@ impl CairoPie { }; let memory = read_memory_file(zip.by_name("memory.bin")?, addr_size, felt_bytes)?; - Ok(CairoPie { + Ok(Self { metadata, memory, execution_resources, @@ -245,11 +245,19 @@ impl CairoPie { } #[cfg(feature = "std")] - pub fn from_file(path: &Path) -> Result { + 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) + } + + #[cfg(feature = "std")] + 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) } }