pub fn detect_image_type(file: &mut RawFile) -> Result<ImageType> {
    let orig_seek = file
        .seek(SeekFrom::Current(0))
        .map_err(Error::SeekingFile)?;
    file.seek(SeekFrom::Start(0)).map_err(Error::SeekingFile)?;
    let magic = file.read_u32::<BigEndian>().map_err(Error::ReadingHeader)?;
    let image_type = if magic == QCOW_MAGIC {
        ImageType::Qcow2
    } else {
        ImageType::Raw
    };
    file.seek(SeekFrom::Start(orig_seek))
        .map_err(Error::SeekingFile)?;
    Ok(image_type)
}
/// Detect the type of an image file by checking for a valid qcow2 header.
Detect the type of an image file by checking for a valid qcow2 header.
Detect the type of an image file by checking for a valid qcow2 header .
pub fn detect_image_type(file: &mut RawFile) -> Result<ImageType> {
    let orig_seek = file
        .seek(SeekFrom::Current(0))
        .map_err(Error::SeekingFile)?;
    file.seek(SeekFrom::Start(0)).map_err(Error::SeekingFile)?;
    let magic = file.read_u32::<BigEndian>().map_err(Error::ReadingHeader)?;
    let image_type = if magic == QCOW_MAGIC {
        ImageType::Qcow2
    } else {
        ImageType::Raw
    };
    file.seek(SeekFrom::Start(orig_seek))
        .map_err(Error::SeekingFile)?;
    Ok(image_type)
}
pub fn detect_image_type ( file : & mut RawFile ) -> Result < ImageType > { let orig_seek = file . seek ( SeekFrom :: Current ( 0 ) ) . map_err ( Error :: SeekingFile ) ? ; file . seek ( SeekFrom :: Start ( 0 ) ) . map_err ( Error :: SeekingFile ) ? ; let magic = file . read_u32 :: < BigEndian > ( ) . map_err ( Error :: ReadingHeader ) ? ; let image_type = if magic == QCOW_MAGIC { ImageType :: Qcow2 } else { ImageType :: Raw } ; file . seek ( SeekFrom :: Start ( orig_seek ) ) . map_err ( Error :: SeekingFile ) ? ; Ok ( image_type ) }
Detect the type of an image file by checking for a valid qcow2 header.
Detect the type of an image file by checking for a valid qcow2 header .
file
&mut RawFile
file
&mut RawFile