fn save_wasm_to_disk<P: Into<PathBuf>>(dir: P, wasm: &[u8]) -> VmResult<Checksum> {
    // calculate filename
    let checksum = Checksum::generate(wasm);
    let filename = checksum.to_hex();
    let filepath = dir.into().join(&filename);

    // write data to file
    // Since the same filename (a collision resistent hash) cannot be generated from two different byte codes
    // (even if a malicious actor tried), it is safe to override.
    let mut file = OpenOptions::new()
        .write(true)
        .create(true)
        .open(filepath)
        .map_err(|e| VmError::cache_err(format!("Error opening Wasm file for writing: {}", e)))?;
    file.write_all(wasm)
        .map_err(|e| VmError::cache_err(format!("Error writing Wasm file: {}", e)))?;

    Ok(checksum)
}
/// save stores the wasm code in the given directory and returns an ID for lookup.
/// It will create the directory if it doesn't exist.
/// Saving the same byte code multiple times is allowed.
save stores the wasm code in the given directory and returns an ID for lookup.
It will create the directory if it doesn't exist.
Saving the same byte code multiple times is allowed.
save stores the wasm code in the given directory and returns an ID for lookup . It will create the directory if it doesn ' t exist . Saving the same byte code multiple times is allowed .
fn save_wasm_to_disk<P: Into<PathBuf>>(dir: P, wasm: &[u8]) -> VmResult<Checksum> {
    // calculate filename
    let checksum = Checksum::generate(wasm);
    let filename = checksum.to_hex();
    let filepath = dir.into().join(&filename);
    // write data to file
    // Since the same filename (a collision resistent hash) cannot be generated from two different byte codes
    // (even if a malicious actor tried), it is safe to override.
    let mut file = OpenOptions::new()
        .write(true)
        .create(true)
        .open(filepath)
        .map_err(|e| VmError::cache_err(format!("Error opening Wasm file for writing: {}", e)))?;
    file.write_all(wasm)
        .map_err(|e| VmError::cache_err(format!("Error writing Wasm file: {}", e)))?;
    Ok(checksum)
}
fn save_wasm_to_disk < P : Into < PathBuf > > ( dir : P , wasm : & [ u8 ] ) -> VmResult < Checksum > { // calculate filename let checksum = Checksum :: generate ( wasm ) ; let filename = checksum . to_hex ( ) ; let filepath = dir . into ( ) . join ( & filename ) ; // write data to file // Since the same filename (a collision resistent hash) cannot be generated from two different byte codes // (even if a malicious actor tried), it is safe to override. let mut file = OpenOptions :: new ( ) . write ( true ) . create ( true ) . open ( filepath ) . map_err ( | e | VmError :: cache_err ( format ! ( " " e ) ) ) ? ; file . write_all ( wasm ) . map_err ( | e | VmError :: cache_err ( format ! ( " " e ) ) ) ? ; Ok ( checksum ) }
save stores the wasm code in the given directory and returns an ID for lookup.
save stores the wasm code in the given directory and returns an ID for lookup .
dir
P
wasm
&[u8]
dir
P
wasm
&[u8]