[][src]Struct delharc::decode::LhaDecodeReader

pub struct LhaDecodeReader<R> { /* fields omitted */ }

This type provides a convenient way to parse and decode LHA/LZH files.

To read the current archived file's content use the io::Read trait methods on the instance of this type. After reading the whole file, its checksum should be verified using LhaDecodeReader::crc_check.

To parse and decode the next archive file, invoke LhaDecodeReader::next_file.

After parsing the LHA header, a decompressed content of a file can be simply read from the LhaDecodeReader<R>, which decompresses it using a proper decoder, designated in the header, while reading data from the underlying stream.

If the compression method is not supported by the decoder, but otherwise the header has been parsed successfully, invoke LhaDecodeReader::is_decoder_supported to ensure you can actually read the file. Otherwise, trying to read from an unsupported decoder will result in an error.

Implementations

impl<R: Read> LhaDecodeReader<R>[src]

pub fn new(rd: R) -> Result<LhaDecodeReader<R>, LhaDecodeError<R>>[src]

Creates a new instance of LhaDecodeReader<R> after reading and parsing the first header from source.

Provide a stream reader.

Errors

Returns an error if the header could not be read or parsed.

pub fn begin_new(&mut self, rd: R) -> Result<bool, LhaDecodeError<R>>[src]

Attempts to read the first file header from a new source stream and initializes a decoder returning Ok(true) on success. Returns Ok(false) if there are no more headers in the stream.

Provide a stream reader.

When Ok is returned, regardles of the retuned boolean value, the inner reader is being always replaced with the given rd.

When Ok(false) has been returned, trying to read from the decoder will result in an error.

Errors

Returns an error if the header could not be read or parsed. In this instance the inner stream reader is not being replaced by a new one and the provided source stream can be retrieved from the returned error.

pub fn begin_with_header_and_decoder(
    &mut self,
    header: LhaHeader,
    decoder: DecoderAny<Take<R>>
)
[src]

Assigns externally parsed header and decoder to this instance of LhaDecodeReader<R>.

It is up to the caller to make sure the decoder and the header are matching each other.

The decoder should be initialized with the reader limited by the io::Take wrapper with its limit set to the LhaHeader::compressed_size number of bytes.

This method assumes the file will be read and decoded from its beginning.

pub fn next_file(&mut self) -> Result<bool, LhaDecodeError<R>>[src]

Attempts to parse the next file's header.

The remaining content of the previous file is being skipped if the current file's content has not been read entirely.

On success returns Ok(true) if the next header has been read and parsed successfully. If there are no more headers, returns Ok(false).

Errors

Returns an error if the header could not be read or parsed. In this instance the underlying stream source will be taken and returned with the error.

Panics

Panics if called when the underlying stream reader has been already taken.

pub fn header(&self) -> &LhaHeader[src]

Returns a reference to the last parsed file's LhaHeader.

pub fn into_inner(self) -> R[src]

Unwraps the underlying stream reader and returns it.

Panics

Panics if the reader has been already taken.

pub fn take_inner(&mut self) -> Option<R>[src]

Takes the inner stream reader value out of the decoder, leaving a none in its place.

After this call, reading from this instance will result in a panic.

pub fn len(&self) -> u64[src]

Returns the number of remaining bytes of the currently decompressed file to be read.

pub fn is_empty(&self) -> bool[src]

Returns true if the current file has been finished reading or if the file was empty.

pub fn is_present(&self) -> bool[src]

Returns true if an underlying stream reader is present in the decoder.

pub fn is_absent(&self) -> bool[src]

Returns true if an underlying stream reader is absent from the decoder.

An attempt to read file's content in this state will result in a panic.

pub fn crc_is_ok(&self) -> bool[src]

Returns true if the computed CRC-16 matches the checksum in the header.

This should be called after the whole file has been read.

pub fn crc_check(&self) -> Result<u16>[src]

Returns CRC-16 checksum if the computed checksum matches the one in the header. Otherwise returns an error.

This should be called after the whole file has been read.

pub fn is_decoder_supported(&self) -> bool[src]

Returns true if the current file's compression method is supported. If this method returns false, trying to read from the decoder will result in an error. In this instance it is still ok to skip to the next file.

Note

If the variant of compression is CompressionMethod::Lhd this method will return false. In this instance check the result from header's LhaHeader::is_directory to determine what steps should be taken next.

Trait Implementations

impl<R: Debug> Debug for LhaDecodeReader<R>[src]

impl<R: Read> Default for LhaDecodeReader<R>[src]

A default implementation creates an instance of LhaDecodeReader<R> with no reader present and with a phony header.

impl<R: Read> Read for LhaDecodeReader<R>[src]

Auto Trait Implementations

impl<R> RefUnwindSafe for LhaDecodeReader<R> where
    R: RefUnwindSafe

impl<R> Send for LhaDecodeReader<R> where
    R: Send

impl<R> Sync for LhaDecodeReader<R> where
    R: Sync

impl<R> Unpin for LhaDecodeReader<R> where
    R: Unpin

impl<R> UnwindSafe for LhaDecodeReader<R> where
    R: UnwindSafe

Blanket Implementations

impl<T> Any for T where
    T: 'static + ?Sized
[src]

impl<T> Borrow<T> for T where
    T: ?Sized
[src]

impl<T> BorrowMut<T> for T where
    T: ?Sized
[src]

impl<T> From<T> for T[src]

impl<T, U> Into<U> for T where
    U: From<T>, 
[src]

impl<T, U> TryFrom<U> for T where
    U: Into<T>, 
[src]

type Error = Infallible

The type returned in the event of a conversion error.

impl<T, U> TryInto<U> for T where
    U: TryFrom<T>, 
[src]

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.