pub fn load(&mut self, fname: &PathBuf) -> Hopefully<()> {
    // Prebuffered BEAM file should be released as soon as the initial phase
    // is done. TODO: [Performance] Use memmapped file?
    let mut r = BinaryReader::from_file(fname);

    // Parse header and check file FOR1 signature
    let hdr1 = Bytes::from(&b"FOR1"[..]);
    r.ensure_bytes(&hdr1)?;

    let _beam_sz = r.read_u32be();

    // Check BEAM signature
    let hdr2 = Bytes::from(&b"BEAM"[..]);
    r.ensure_bytes(&hdr2)?;

    loop {
      // EOF may strike here when we finished reading
      let chunk_h = match r.read_str_latin1(4) {
        Ok(s) => s,
        // EOF is not an error
        Err(ReadError::PrematureEOF) => break,
        Err(e) => return Err(Error::CodeLoading(e))
      };
      let chunk_sz = r.read_u32be();
      let pos_begin = r.pos();

      //println!("Chunk {}", chunk_h);
      match chunk_h.as_ref() {
        "Atom" => self.load_atoms_latin1(&mut r),
        "Attr" => self.load_attributes(&mut r)?,
        "AtU8" => self.load_atoms_utf8(&mut r),
        "CInf" => self.load_compiler_info(&mut r)?,
        "Code" => self.load_code(&mut r, chunk_sz as Word),
        "ExpT" => self.raw.exports = self.load_exports(&mut r),
        "FunT" => self.load_fun_table(&mut r),
        "ImpT" => self.load_imports(&mut r),
        "Line" => self.load_line_info(&mut r),
        "LitT" => self.load_literals(&mut r, chunk_sz as Word),
        // LocT same format as ExpT, but for local functions
        "LocT" => self.raw.locals = self.load_exports(&mut r),

        "Dbgi" | // skip debug info
        "StrT" | // skip strings TODO load strings?
        "Abst" => r.skip(chunk_sz as Word), // skip abstract code

        other => {
          let msg = format!("{}Unexpected chunk: {}", module(), other);
          return Err(Error::CodeLoadingFailed(msg))
        }
      }

      // The next chunk is aligned at 4 bytes
      let aligned_sz = 4 * ((chunk_sz + 3) / 4);
      r.seek(pos_begin + aligned_sz as Word);
    }

    Ok(())
  }
/// Loading the module. Validate the header and iterate over sections,
/// then call `load_stage2()` to apply changes to the VM, and then finalize
/// it by calling `load_finalize()` which will return you a module object.
Loading the module. Validate the header and iterate over sections,
then call `load_stage2()` to apply changes to the VM, and then finalize
it by calling `load_finalize()` which will return you a module object.
Loading the module . Validate the header and iterate over sections then call ` load_stage2 () ` to apply changes to the VM and then finalize it by calling ` load_finalize () ` which will return you a module object .
pub fn load(&mut self, fname: &PathBuf) -> Hopefully<()> {
    // Prebuffered BEAM file should be released as soon as the initial phase
    // is done. TODO: [Performance] Use memmapped file?
    let mut r = BinaryReader::from_file(fname);
    // Parse header and check file FOR1 signature
    let hdr1 = Bytes::from(&b"FOR1"[..]);
    r.ensure_bytes(&hdr1)?;
    let _beam_sz = r.read_u32be();
    // Check BEAM signature
    let hdr2 = Bytes::from(&b"BEAM"[..]);
    r.ensure_bytes(&hdr2)?;
    loop {
      // EOF may strike here when we finished reading
      let chunk_h = match r.read_str_latin1(4) {
        Ok(s) => s,
        // EOF is not an error
        Err(ReadError::PrematureEOF) => break,
        Err(e) => return Err(Error::CodeLoading(e))
      };
      let chunk_sz = r.read_u32be();
      let pos_begin = r.pos();
      //println!("Chunk {}", chunk_h);
      match chunk_h.as_ref() {
        "Atom" => self.load_atoms_latin1(&mut r),
        "Attr" => self.load_attributes(&mut r)?,
        "AtU8" => self.load_atoms_utf8(&mut r),
        "CInf" => self.load_compiler_info(&mut r)?,
        "Code" => self.load_code(&mut r, chunk_sz as Word),
        "ExpT" => self.raw.exports = self.load_exports(&mut r),
        "FunT" => self.load_fun_table(&mut r),
        "ImpT" => self.load_imports(&mut r),
        "Line" => self.load_line_info(&mut r),
        "LitT" => self.load_literals(&mut r, chunk_sz as Word),
        // LocT same format as ExpT, but for local functions
        "LocT" => self.raw.locals = self.load_exports(&mut r),
        "Dbgi" | // skip debug info
        "StrT" | // skip strings TODO load strings?
        "Abst" => r.skip(chunk_sz as Word), // skip abstract code
        other => {
          let msg = format!("{}Unexpected chunk: {}", module(), other);
          return Err(Error::CodeLoadingFailed(msg))
        }
      }
      // The next chunk is aligned at 4 bytes
      let aligned_sz = 4 * ((chunk_sz + 3) / 4);
      r.seek(pos_begin + aligned_sz as Word);
    }
    Ok(())
  }
pub fn load ( & mut self , fname : & PathBuf ) -> Hopefully < ( ) > { // Prebuffered BEAM file should be released as soon as the initial phase // is done. TODO: [Performance] Use memmapped file? let mut r = BinaryReader :: from_file ( fname ) ; // Parse header and check file FOR1 signature let hdr1 = Bytes :: from ( & b" " [ .. ] ) ; r . ensure_bytes ( & hdr1 ) ? ; let _beam_sz = r . read_u32be ( ) ; // Check BEAM signature let hdr2 = Bytes :: from ( & b" " [ .. ] ) ; r . ensure_bytes ( & hdr2 ) ? ; loop { // EOF may strike here when we finished reading let chunk_h = match r . read_str_latin1 ( 4 ) { Ok ( s ) => s , // EOF is not an error Err ( ReadError :: PrematureEOF ) => break , Err ( e ) => return Err ( Error :: CodeLoading ( e ) ) } ; let chunk_sz = r . read_u32be ( ) ; let pos_begin = r . pos ( ) ; //println!("Chunk {}", chunk_h); match chunk_h . as_ref ( ) { " " => self . load_atoms_latin1 ( & mut r ) , " " => self . load_attributes ( & mut r ) ? , " " => self . load_atoms_utf8 ( & mut r ) , " " => self . load_compiler_info ( & mut r ) ? , " " => self . load_code ( & mut r , chunk_sz as Word ) , " " => self . raw . exports = self . load_exports ( & mut r ) , " " => self . load_fun_table ( & mut r ) , " " => self . load_imports ( & mut r ) , " " => self . load_line_info ( & mut r ) , " " => self . load_literals ( & mut r , chunk_sz as Word ) , // LocT same format as ExpT, but for local functions " " => self . raw . locals = self . load_exports ( & mut r ) , " " | // skip debug info " " | // skip strings TODO load strings? " " => r . skip ( chunk_sz as Word ) , // skip abstract code other => { let msg = format ! ( " " module ( ) other ) ; return Err ( Error :: CodeLoadingFailed ( msg ) ) } } // The next chunk is aligned at 4 bytes let aligned_sz = 4 * ( ( chunk_sz + 3 ) / 4 ) ; r . seek ( pos_begin + aligned_sz as Word ) ; } Ok ( ( ) ) }
Loading the module.
Loading the module .
&mut self
fname
&PathBuf