fn write_data(
        &self,
        in_stream: &mut dyn ReadAndSeek,
        out_stream: &mut dyn Write,
    ) -> Result<u64, Error> {
        let mut size = 0;
        for (_, extent) in &self.extent_tree {
            // No need to dump the data. Only ExtentInfo will be written to the image file.
            if !should_dump_data(&extent, self.options.force_dump_pii) {
                continue;
            }
            let bytes_to_read = extent.storage_range().length();
            let mut read_buffer: Vec<u8> = vec![0; bytes_to_read as usize];
            let offset = extent.storage_range().start;
            // Seek to the storage location.
            in_stream.seek(std::io::SeekFrom::Start(offset)).map_err(move |_| Error::SeekFailed)?;
            let mut r = in_stream.take(bytes_to_read);

            // Read from the storage.
            r.read(&mut read_buffer[..bytes_to_read as usize]).map_err(move |_| {
                eprintln!(
                    "Failed to read {} bytes from {} offset for {:?}",
                    bytes_to_read, offset, extent
                );
                Error::ReadFailed
            })?;

            // Write to the image file
            out_stream.write_all(&read_buffer).map_err(move |_| Error::WriteFailed)?;
            size = size + bytes_to_read;
        }
        Ok(size)
    }
/// Write all the data in extents to the out_stream.
///
/// The extent's data is read from the in_stream.
Write all the data in extents to the out_stream.
The extent's data is read from the in_stream.
Write all the data in extents to the out_stream . The extent ' s data is read from the in_stream .
fn write_data(
        &self,
        in_stream: &mut dyn ReadAndSeek,
        out_stream: &mut dyn Write,
    ) -> Result<u64, Error> {
        let mut size = 0;
        for (_, extent) in &self.extent_tree {
            // No need to dump the data. Only ExtentInfo will be written to the image file.
            if !should_dump_data(&extent, self.options.force_dump_pii) {
                continue;
            }
            let bytes_to_read = extent.storage_range().length();
            let mut read_buffer: Vec<u8> = vec![0; bytes_to_read as usize];
            let offset = extent.storage_range().start;
            // Seek to the storage location.
            in_stream.seek(std::io::SeekFrom::Start(offset)).map_err(move |_| Error::SeekFailed)?;
            let mut r = in_stream.take(bytes_to_read);
            // Read from the storage.
            r.read(&mut read_buffer[..bytes_to_read as usize]).map_err(move |_| {
                eprintln!(
                    "Failed to read {} bytes from {} offset for {:?}",
                    bytes_to_read, offset, extent
                );
                Error::ReadFailed
            })?;
            // Write to the image file
            out_stream.write_all(&read_buffer).map_err(move |_| Error::WriteFailed)?;
            size = size + bytes_to_read;
        }
        Ok(size)
    }
fn write_data ( & self , in_stream : & mut dyn ReadAndSeek , out_stream : & mut dyn Write , ) -> Result < u64 , Error > { let mut size = 0 ; for ( _ , extent ) in & self . extent_tree { // No need to dump the data. Only ExtentInfo will be written to the image file. if ! should_dump_data ( & extent , self . options . force_dump_pii ) { continue ; } let bytes_to_read = extent . storage_range ( ) . length ( ) ; let mut read_buffer : Vec < u8 > = vec ! [ 0 bytes_to_read as usize ] ; let offset = extent . storage_range ( ) . start ; // Seek to the storage location. in_stream . seek ( std :: io :: SeekFrom :: Start ( offset ) ) . map_err ( move | _ | Error :: SeekFailed ) ? ; let mut r = in_stream . take ( bytes_to_read ) ; // Read from the storage. r . read ( & mut read_buffer [ .. bytes_to_read as usize ] ) . map_err ( move | _ | { eprintln ! ( " " bytes_to_read offset extent ) ; Error :: ReadFailed } ) ? ; // Write to the image file out_stream . write_all ( & read_buffer ) . map_err ( move | _ | Error :: WriteFailed ) ? ; size = size + bytes_to_read ; } Ok ( size ) }
Write all the data in extents to the out_stream.
Write all the data in extents to the out_stream .
&self
in_stream
&mut dyn ReadAndSeek
out_stream
&mut dyn Write
&self
in_stream
&mut dyn ReadAndSeek
out_stream
&mut dyn Write