pub fn write(
        &mut self,
        path: &str,
        mut write_data: Vec<il::Expression>,
        offset: usize,
    ) -> Result<()> {
        println!("Calling write {}", path);
        if let Some(data) = self.files.get_mut(path) {
            if offset > data.len() {
                for _ in 0..(offset - data.len()) {
                    RC::make_mut(data).push(il::expr_const(0, 8));
                }
            }

            if offset == data.len() {
                RC::make_mut(data).append(&mut write_data);
            } else {
                let mut new_data = data
                    .get(0..offset)
                    .map(|data| data.to_vec())
                    .ok_or("Failed to get data bytes")?;
                new_data.append(&mut write_data);
                if data.len() > offset + write_data.len() {
                    new_data.append(
                        &mut data
                            .get((offset + write_data.len())..data.len())
                            .ok_or("Failed to get data bytes")?
                            .to_vec(),
                    );
                }
                *data = RC::new(new_data);
            }
            return Ok(());
        }

        let mut data: Vec<il::Expression> = Vec::new();
        for _ in 0..offset {
            data.push(il::expr_const(0, 8));
        }
        data.append(&mut write_data);
        self.files.insert(path.to_string(), RC::new(data));

        Ok(())
    }
/// Write data into a file at an offset
Write data into a file at an offset
Write data into a file at an offset
pub fn write(
        &mut self,
        path: &str,
        mut write_data: Vec<il::Expression>,
        offset: usize,
    ) -> Result<()> {
        println!("Calling write {}", path);
        if let Some(data) = self.files.get_mut(path) {
            if offset > data.len() {
                for _ in 0..(offset - data.len()) {
                    RC::make_mut(data).push(il::expr_const(0, 8));
                }
            }
            if offset == data.len() {
                RC::make_mut(data).append(&mut write_data);
            } else {
                let mut new_data = data
                    .get(0..offset)
                    .map(|data| data.to_vec())
                    .ok_or("Failed to get data bytes")?;
                new_data.append(&mut write_data);
                if data.len() > offset + write_data.len() {
                    new_data.append(
                        &mut data
                            .get((offset + write_data.len())..data.len())
                            .ok_or("Failed to get data bytes")?
                            .to_vec(),
                    );
                }
                *data = RC::new(new_data);
            }
            return Ok(());
        }
        let mut data: Vec<il::Expression> = Vec::new();
        for _ in 0..offset {
            data.push(il::expr_const(0, 8));
        }
        data.append(&mut write_data);
        self.files.insert(path.to_string(), RC::new(data));
        Ok(())
    }
pub fn write ( & mut self , path : & str , mut write_data : Vec < il :: Expression > , offset : usize , ) -> Result < ( ) > { println ! ( " " path ) ; if let Some ( data ) = self . files . get_mut ( path ) { if offset > data . len ( ) { for _ in 0 .. ( offset - data . len ( ) ) { RC :: make_mut ( data ) . push ( il :: expr_const ( 0 , 8 ) ) ; } } if offset == data . len ( ) { RC :: make_mut ( data ) . append ( & mut write_data ) ; } else { let mut new_data = data . get ( 0 .. offset ) . map ( | data | data . to_vec ( ) ) . ok_or ( " " ) ? ; new_data . append ( & mut write_data ) ; if data . len ( ) > offset + write_data . len ( ) { new_data . append ( & mut data . get ( ( offset + write_data . len ( ) ) .. data . len ( ) ) . ok_or ( " " ) ? . to_vec ( ) , ) ; } * data = RC :: new ( new_data ) ; } return Ok ( ( ) ) ; } let mut data : Vec < il :: Expression > = Vec :: new ( ) ; for _ in 0 .. offset { data . push ( il :: expr_const ( 0 , 8 ) ) ; } data . append ( & mut write_data ) ; self . files . insert ( path . to_string ( ) , RC :: new ( data ) ) ; Ok ( ( ) ) }
Write data into a file at an offset
Write data into a file at an offset
&mut self
path
&str
write_data
Vec<il::Expression>
offset
usize