pub struct TapChunkReader<R> {
    pub checksum: u8,
    /* private fields */
}
Expand description

Implements a Reader of TAP chunks data.

Implements reader that reads only up to the size of the current TAP chunk.

Fields§

§checksum: u8

The checksum is being updated when reading via Read methods from a TapChunkReader.

Implementations§

Returns the wrapped reader.

Returns a reference to the chunk’s Take reader.

Returns a mutable reference to the chunk’s Take reader.

Examples found in repository?
src/tap/read.rs (line 355)
352
353
354
355
356
357
358
359
    fn next(&mut self) -> Option<Self::Item> {
        let info = match self.inner.next_chunk() {
            Ok(None) => return None,
            Ok(_) => TapChunkInfo::try_from(self.inner.get_mut()),
            Err(e) => return Some(Err(e))
        };
        Some(info)
    }
More examples
Hide additional examples
src/mdr.rs (line 789)
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
    fn file_from_tap_reader<R: Read + Seek>(&mut self, rd: &mut TapChunkReader<R>) -> io::Result<u8> {
        if rd.chunk_limit() == 0 {
            rd.next_chunk()?;
        }
        let header = if let TapChunkInfo::Head(header) = TapChunkInfo::try_from(rd.get_mut())? {
            header
        }
        else {
            return Err(io::Error::new(io::ErrorKind::InvalidData, "not a TAP header"))
        };
        if let Some(chunk_size) = rd.next_chunk()? {
            if chunk_size < 2 || header.length != chunk_size - 2 {
                return Err(io::Error::new(io::ErrorKind::InvalidData, "not a TAP block"))
            }
            let mut flag = 0u8;
            rd.read_exact(slice::from_mut(&mut flag))?;
            if flag != DATA_BLOCK_FLAG {
                return Err(io::Error::new(io::ErrorKind::InvalidData, "invalid TAP block flag"))
            }
        }
        else {
            return Err(io::Error::new(io::ErrorKind::InvalidData, "missing TAP chunk"))
        }
        let fbheader = MdrFileHeader::from(&header).into_array();
        let hdrd = io::Cursor::new(fbheader).chain(rd.take(header.length as u64));
        let res = self.store_file(header.name, true, hdrd)?;
        {
            let mut checksum = 0u8;
            let res = rd.read_exact(slice::from_mut(&mut checksum));
            if res.is_err() || rd.checksum != 0 {
                self.erase_file(header.name);
                return Err(io::Error::new(io::ErrorKind::InvalidData, "TAP block checksum error"))
            }
        }
        Ok(res)
    }

Creates a new instance of TapChunkReader from the reader with an assumption that the next two bytes read from it will form the next chunk header.

chunk_no should be the chunk number of the previous chunk.

Creates a clone of self but with a mutable reference to the underlying reader.

Returns a guard that, when dropped, will try to restore the original position of the reader. However to check if it succeeded it’s better to use TapChunkReaderMut::done method directly on the guard which returns a result from the seek operation.

Trait Implementations§

Converts this type into a mutable reference of the (usually inferred) input type.
Converts this type into a mutable reference of the (usually inferred) input type.
Converts this type into a shared reference of the (usually inferred) input type.
Converts this type into a shared reference of the (usually inferred) input type.
Formats the value using the given formatter. Read more
Converts to this type from the input type.
Converts to this type from the input type.
Pull some bytes from this source into the specified buffer, returning how many bytes were read. Read more
Read all bytes until EOF in this source, placing them into buf. Read more
Like read, except that it reads into a slice of buffers. Read more
🔬This is a nightly-only experimental API. (can_vector)
Determines if this Reader has an efficient read_vectored implementation. Read more
Read all bytes until EOF in this source, appending them to buf. Read more
Read the exact number of bytes required to fill buf. Read more
🔬This is a nightly-only experimental API. (read_buf)
Pull some bytes from this source into the specified buffer. Read more
🔬This is a nightly-only experimental API. (read_buf)
Read the exact number of bytes required to fill cursor. Read more
Creates a “by reference” adaptor for this instance of Read. Read more
Transforms this Read instance to an Iterator over its bytes. Read more
Creates an adapter which will chain this stream with another. Read more
Creates an adapter which will read at most limit bytes from it. Read more
Returns this chunk’s number. Read more
Returns this chunk’s remaining bytes to be read.
Repositions the inner reader to the start of a file and sets the inner limit to 0. To read the first chunk you need to call TapChunkRead::next_chunk first. Read more
Forwards the inner reader to the position of a next skip + 1 TAP chunks. Returns Ok(None) if the end of the file has been reached. On success returns Ok(size) in bytes of the next TAP chunk and limits the inner Take reader to that size. Read more
Rewinds or forwards the tape to the nth chunk. Returns Ok(true) if the nth chunk exists. Otherwise returns Ok(false) and leaves the seek position at the end of the tape. Read more
Forwards the tape to the next chunk. Returns Ok(true) if the forwarded to chunk exists. Otherwise returns Ok(false) and leaves the seek position at the end of the tape. Read more
Rewinds the tape to the beginning of the previous chunk. Returns Ok(chunk_no).
Rewinds the tape to the beginning of the current chunk. Returns Ok(chunk_no).
The type returned in the event of a conversion error.
Performs the conversion.

Auto Trait Implementations§

Blanket Implementations§

Gets the TypeId of self. Read more
Immutably borrows from an owned value. Read more
Mutably borrows from an owned value. Read more
Converts self into T using Into<T>. Read more
Causes self to use its Binary implementation when Debug-formatted.
Causes self to use its Display implementation when Debug-formatted. Read more
Causes self to use its LowerExp implementation when Debug-formatted. Read more
Causes self to use its LowerHex implementation when Debug-formatted. Read more
Causes self to use its Octal implementation when Debug-formatted.
Causes self to use its Pointer implementation when Debug-formatted. Read more
Causes self to use its UpperExp implementation when Debug-formatted. Read more
Causes self to use its UpperHex implementation when Debug-formatted. Read more
Formats each item in a sequence. Read more

Returns the argument unchanged.

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Convert to S a sample type from self.
Pipes by value. This is generally the method you want to use. Read more
Borrows self and passes that borrow into the pipe function. Read more
Mutably borrows self and passes that borrow into the pipe function. Read more
Borrows self, then passes self.borrow() into the pipe function. Read more
Mutably borrows self, then passes self.borrow_mut() into the pipe function. Read more
Borrows self, then passes self.as_ref() into the pipe function.
Mutably borrows self, then passes self.as_mut() into the pipe function. Read more
Borrows self, then passes self.deref() into the pipe function.
Mutably borrows self, then passes self.deref_mut() into the pipe function. Read more
Reads all bytes to fill buf or until EOF. If successful, returns the total number of bytes read. Read more
Reads the exact number of bytes required to fill buf and returns Ok(true) or returns Ok(false) if exactly zero bytes were read. In this instance, buf will be left unmodified. Read more
Immutable access to a value. Read more
Mutable access to a value. Read more
Immutable access to the Borrow<B> of a value. Read more
Mutable access to the BorrowMut<B> of a value. Read more
Immutable access to the AsRef<R> view of a value. Read more
Mutable access to the AsMut<R> view of a value. Read more
Immutable access to the Deref::Target of a value. Read more
Mutable access to the Deref::Target of a value. Read more
Calls .tap() only in debug builds, and is erased in release builds.
Calls .tap_mut() only in debug builds, and is erased in release builds. Read more
Calls .tap_borrow() only in debug builds, and is erased in release builds. Read more
Calls .tap_borrow_mut() only in debug builds, and is erased in release builds. Read more
Calls .tap_ref() only in debug builds, and is erased in release builds. Read more
Calls .tap_ref_mut() only in debug builds, and is erased in release builds. Read more
Calls .tap_deref() only in debug builds, and is erased in release builds. Read more
Calls .tap_deref_mut() only in debug builds, and is erased in release builds. Read more
Attempts to convert self into T using TryInto<T>. Read more
The type returned in the event of a conversion error.
Performs the conversion.
The type returned in the event of a conversion error.
Performs the conversion.