pub fn read_at(&mut self, buf: &mut [u8], offset: u64) -> io::Result<usize> {
        //println!("0. read_at(buf[0..{}], {})", buf.len(), offset);
        let mut buf = buf;
        let mut offset = offset;
        let mut done = 0;

        // Does the offset start in the init section?
        if offset < self.init_size as u64 {
            // Yep, so read the init section.
            let init_section = match self.init_section.as_ref() {
                Some(data) => data,
                None => {
                    let init_section = InitSection::init_section(&self.key)?;
                    let mut buf = crate::io::MemBuffer::new();
                    init_section.init.write(&mut buf)?;
                    self.init_section = Some(buf.into_vec());
                    self.init_section.as_ref().unwrap()
                },
            };

            // Copy to buf.
            let init_size = self.init_size as usize;
            let u_offset = offset as usize;
            let len = std::cmp::min(buf.len(), init_size - u_offset);
            buf[..len].copy_from_slice(&init_section[u_offset..u_offset + len]);

            // advance buf and offset. if there is space in buf left,
            // we'll start reading from the MdatMapping.
            done = len;
            buf = &mut buf[len..];
            offset += len as u64;
        }

        if buf.len() == 0 {
            return Ok(done);
        }

        // Okay we have to map the mdat section.
        let mapping = InitSection::mapping(&self.key)?;
        let n = mapping.read_at(&self.file, self.mmap.as_ref(), buf, offset)?;
        done += n;
        //println!("read {} bytes ({} via mapping)", done, n);
        Ok(done)
    }
/// Read data at a certain offset.
Read data at a certain offset.
Read data at a certain offset .
pub fn read_at(&mut self, buf: &mut [u8], offset: u64) -> io::Result<usize> {
        //println!("0. read_at(buf[0..{}], {})", buf.len(), offset);
        let mut buf = buf;
        let mut offset = offset;
        let mut done = 0;
        // Does the offset start in the init section?
        if offset < self.init_size as u64 {
            // Yep, so read the init section.
            let init_section = match self.init_section.as_ref() {
                Some(data) => data,
                None => {
                    let init_section = InitSection::init_section(&self.key)?;
                    let mut buf = crate::io::MemBuffer::new();
                    init_section.init.write(&mut buf)?;
                    self.init_section = Some(buf.into_vec());
                    self.init_section.as_ref().unwrap()
                },
            };
            // Copy to buf.
            let init_size = self.init_size as usize;
            let u_offset = offset as usize;
            let len = std::cmp::min(buf.len(), init_size - u_offset);
            buf[..len].copy_from_slice(&init_section[u_offset..u_offset + len]);
            // advance buf and offset. if there is space in buf left,
            // we'll start reading from the MdatMapping.
            done = len;
            buf = &mut buf[len..];
            offset += len as u64;
        }
        if buf.len() == 0 {
            return Ok(done);
        }
        // Okay we have to map the mdat section.
        let mapping = InitSection::mapping(&self.key)?;
        let n = mapping.read_at(&self.file, self.mmap.as_ref(), buf, offset)?;
        done += n;
        //println!("read {} bytes ({} via mapping)", done, n);
        Ok(done)
    }
pub fn read_at ( & mut self , buf : & mut [ u8 ] , offset : u64 ) -> io :: Result < usize > { //println!("0. read_at(buf[0..{}], {})", buf.len(), offset); let mut buf = buf ; let mut offset = offset ; let mut done = 0 ; // Does the offset start in the init section? if offset < self . init_size as u64 { // Yep, so read the init section. let init_section = match self . init_section . as_ref ( ) { Some ( data ) => data , None => { let init_section = InitSection :: init_section ( & self . key ) ? ; let mut buf = crate :: io :: MemBuffer :: new ( ) ; init_section . init . write ( & mut buf ) ? ; self . init_section = Some ( buf . into_vec ( ) ) ; self . init_section . as_ref ( ) . unwrap ( ) } , } ; // Copy to buf. let init_size = self . init_size as usize ; let u_offset = offset as usize ; let len = std :: cmp :: min ( buf . len ( ) , init_size - u_offset ) ; buf [ .. len ] . copy_from_slice ( & init_section [ u_offset .. u_offset + len ] ) ; // advance buf and offset. if there is space in buf left, // we'll start reading from the MdatMapping. done = len ; buf = & mut buf [ len .. ] ; offset += len as u64 ; } if buf . len ( ) == 0 { return Ok ( done ) ; } // Okay we have to map the mdat section. let mapping = InitSection :: mapping ( & self . key ) ? ; let n = mapping . read_at ( & self . file , self . mmap . as_ref ( ) , buf , offset ) ? ; done += n ; //println!("read {} bytes ({} via mapping)", done, n); Ok ( done ) }
Read data at a certain offset.
Read data at a certain offset .
&mut self
buf
&mut [u8]
offset
u64
&mut self
buf
&mut [u8]
offset
u64