pub fn new<R: Read>(mut reader: &mut R, len: usize) -> Result<Cfb, CfbError> {
        // load header
        let (h, mut difat) = Header::from_reader(&mut reader)?;
        let mut sectors = Sectors::new(h.sector_size, Vec::with_capacity(len));

        // load fat and dif sectors
        debug!("load difat");
        let mut sector_id = h.difat_start;
        while sector_id < RESERVED_SECTORS {
            difat.extend(to_u32(sectors.get(sector_id, reader)?));
            sector_id = difat.pop().unwrap(); //TODO: check if in infinite loop
        }

        // load the FATs
        debug!("load fat (len {})", h.fat_len);
        let mut fats = Vec::with_capacity(h.fat_len);
        for id in difat.into_iter().filter(|id| *id < DIFSECT) {
            fats.extend(to_u32(sectors.get(id, reader)?));
        }

        // get the list of directory sectors
        debug!("load directories");
        let dirs = sectors.get_chain(h.dir_start, &fats, reader, h.dir_len * h.sector_size)?;
        let dirs = dirs
            .chunks(128)
            .map(|c| Directory::from_slice(c, h.sector_size))
            .collect::<Vec<_>>();

        if dirs.is_empty() || (h.version != 3 && dirs[0].start == ENDOFCHAIN) {
            return Err(CfbError::EmptyRootDir);
        }
        debug!("{:?}", dirs);

        // load the mini streams
        debug!("load minis");
        let ministream = sectors.get_chain(dirs[0].start, &fats, reader, dirs[0].len)?;
        let minifat = sectors.get_chain(
            h.mini_fat_start,
            &fats,
            reader,
            h.mini_fat_len * h.sector_size,
        )?;
        let minifat = to_u32(&minifat).collect();
        Ok(Cfb {
            directories: dirs,
            sectors,
            fats,
            mini_sectors: Sectors::new(64, ministream),
            mini_fats: minifat,
        })
    }
/// Create a new `Cfb`
///
/// Starts reading project metadata (header, directories, sectors and minisectors).
Create a new `Cfb`
Starts reading project metadata (header, directories, sectors and minisectors).
Create a new ` Cfb ` Starts reading project metadata ( header directories sectors and minisectors ) .
pub fn new<R: Read>(mut reader: &mut R, len: usize) -> Result<Cfb, CfbError> {
        // load header
        let (h, mut difat) = Header::from_reader(&mut reader)?;
        let mut sectors = Sectors::new(h.sector_size, Vec::with_capacity(len));
        // load fat and dif sectors
        debug!("load difat");
        let mut sector_id = h.difat_start;
        while sector_id < RESERVED_SECTORS {
            difat.extend(to_u32(sectors.get(sector_id, reader)?));
            sector_id = difat.pop().unwrap(); //TODO: check if in infinite loop
        }
        // load the FATs
        debug!("load fat (len {})", h.fat_len);
        let mut fats = Vec::with_capacity(h.fat_len);
        for id in difat.into_iter().filter(|id| *id < DIFSECT) {
            fats.extend(to_u32(sectors.get(id, reader)?));
        }
        // get the list of directory sectors
        debug!("load directories");
        let dirs = sectors.get_chain(h.dir_start, &fats, reader, h.dir_len * h.sector_size)?;
        let dirs = dirs
            .chunks(128)
            .map(|c| Directory::from_slice(c, h.sector_size))
            .collect::<Vec<_>>();
        if dirs.is_empty() || (h.version != 3 && dirs[0].start == ENDOFCHAIN) {
            return Err(CfbError::EmptyRootDir);
        }
        debug!("{:?}", dirs);
        // load the mini streams
        debug!("load minis");
        let ministream = sectors.get_chain(dirs[0].start, &fats, reader, dirs[0].len)?;
        let minifat = sectors.get_chain(
            h.mini_fat_start,
            &fats,
            reader,
            h.mini_fat_len * h.sector_size,
        )?;
        let minifat = to_u32(&minifat).collect();
        Ok(Cfb {
            directories: dirs,
            sectors,
            fats,
            mini_sectors: Sectors::new(64, ministream),
            mini_fats: minifat,
        })
    }
pub fn new < R : Read > ( mut reader : & mut R , len : usize ) -> Result < Cfb , CfbError > { // load header let ( h , mut difat ) = Header :: from_reader ( & mut reader ) ? ; let mut sectors = Sectors :: new ( h . sector_size , Vec :: with_capacity ( len ) ) ; // load fat and dif sectors debug ! ( " " ) ; let mut sector_id = h . difat_start ; while sector_id < RESERVED_SECTORS { difat . extend ( to_u32 ( sectors . get ( sector_id , reader ) ? ) ) ; sector_id = difat . pop ( ) . unwrap ( ) ; //TODO: check if in infinite loop } // load the FATs debug ! ( " " h fat_len ) ; let mut fats = Vec :: with_capacity ( h . fat_len ) ; for id in difat . into_iter ( ) . filter ( | id | * id < DIFSECT ) { fats . extend ( to_u32 ( sectors . get ( id , reader ) ? ) ) ; } // get the list of directory sectors debug ! ( " " ) ; let dirs = sectors . get_chain ( h . dir_start , & fats , reader , h . dir_len * h . sector_size ) ? ; let dirs = dirs . chunks ( 128 ) . map ( | c | Directory :: from_slice ( c , h . sector_size ) ) . collect :: < Vec < _ > > ( ) ; if dirs . is_empty ( ) || ( h . version != 3 && dirs [ 0 ] . start == ENDOFCHAIN ) { return Err ( CfbError :: EmptyRootDir ) ; } debug ! ( " " dirs ) ; // load the mini streams debug ! ( " " ) ; let ministream = sectors . get_chain ( dirs [ 0 ] . start , & fats , reader , dirs [ 0 ] . len ) ? ; let minifat = sectors . get_chain ( h . mini_fat_start , & fats , reader , h . mini_fat_len * h . sector_size , ) ? ; let minifat = to_u32 ( & minifat ) . collect ( ) ; Ok ( Cfb { directories : dirs , sectors , fats , mini_sectors : Sectors :: new ( 64 , ministream ) , mini_fats : minifat , } ) }
Create a new `Cfb`
Starts reading project metadata (header, directories, sectors and minisectors).
Create a new ` Cfb ` Starts reading project metadata ( header directories sectors and minisectors ) .
reader
&mut R
len
usize