[−][src]Struct delharc::decode::LhaDecodeReader
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]
&mut self,
header: LhaHeader,
decoder: DecoderAny<Take<R>>
)
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]
fn read(&mut self, buf: &mut [u8]) -> Result<usize>
[src]
fn read_vectored(&mut self, bufs: &mut [IoSliceMut]) -> Result<usize, Error>
1.36.0[src]
fn is_read_vectored(&self) -> bool
[src]
unsafe fn initializer(&self) -> Initializer
[src]
fn read_to_end(&mut self, buf: &mut Vec<u8>) -> Result<usize, Error>
1.0.0[src]
fn read_to_string(&mut self, buf: &mut String) -> Result<usize, Error>
1.0.0[src]
fn read_exact(&mut self, buf: &mut [u8]) -> Result<(), Error>
1.6.0[src]
fn by_ref(&mut self) -> &mut Self
1.0.0[src]
fn bytes(self) -> Bytes<Self>
1.0.0[src]
fn chain<R>(self, next: R) -> Chain<Self, R> where
R: Read,
1.0.0[src]
R: Read,
fn take(self, limit: u64) -> Take<Self>
1.0.0[src]
Auto Trait Implementations
impl<R> RefUnwindSafe for LhaDecodeReader<R> where
R: RefUnwindSafe,
R: RefUnwindSafe,
impl<R> Send for LhaDecodeReader<R> where
R: Send,
R: Send,
impl<R> Sync for LhaDecodeReader<R> where
R: Sync,
R: Sync,
impl<R> Unpin for LhaDecodeReader<R> where
R: Unpin,
R: Unpin,
impl<R> UnwindSafe for LhaDecodeReader<R> where
R: UnwindSafe,
R: UnwindSafe,
Blanket Implementations
impl<T> Any for T where
T: 'static + ?Sized,
[src]
T: 'static + ?Sized,
impl<T> Borrow<T> for T where
T: ?Sized,
[src]
T: ?Sized,
impl<T> BorrowMut<T> for T where
T: ?Sized,
[src]
T: ?Sized,
fn borrow_mut(&mut self) -> &mut T
[src]
impl<T> From<T> for T
[src]
impl<T, U> Into<U> for T where
U: From<T>,
[src]
U: From<T>,
impl<T, U> TryFrom<U> for T where
U: Into<T>,
[src]
U: Into<T>,
type Error = Infallible
The type returned in the event of a conversion error.
fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>
[src]
impl<T, U> TryInto<U> for T where
U: TryFrom<T>,
[src]
U: TryFrom<T>,