OpenMS
Bzip2Ifstream Class Reference

Decompresses files which are compressed in the bzip2 format (*.bz2) More...

#include <OpenMS/FORMAT/Bzip2Ifstream.h>

Collaboration diagram for Bzip2Ifstream:
[legend]

Public Member Functions

 Bzip2Ifstream ()
 Default Constructor. More...
 
 Bzip2Ifstream (const char *filename)
 Detailed constructor with filename. More...
 
virtual ~Bzip2Ifstream ()
 Destructor. More...
 
size_t read (char *s, size_t n)
 Reads n bytes from the bzip2 compressed file into buffer s. More...
 
bool streamEnd () const
 indicates whether the read function can be used safely More...
 
bool isOpen () const
 returns whether a file is open. More...
 
void open (const char *filename)
 opens a file for reading (decompression) More...
 
void close ()
 closes current file. More...
 

Protected Member Functions

 Bzip2Ifstream (const Bzip2Ifstream &bzip2)
 
Bzip2Ifstreamoperator= (const Bzip2Ifstream &bzip2)
 

Protected Attributes

FILE * file_
 pointer to a FILE object. Necessary for opening the file More...
 
BZFILE * bzip2file_
 a pointer to a BZFILE object. Necessary for decompression More...
 
size_t n_buffer_
 counts the last read buffer More...
 
int bzerror_
 saves the last returned error by the read function More...
 
bool stream_at_end_
 true if end of file is reached More...
 

Detailed Description

Decompresses files which are compressed in the bzip2 format (*.bz2)

Constructor & Destructor Documentation

◆ Bzip2Ifstream() [1/3]

Default Constructor.

◆ Bzip2Ifstream() [2/3]

Bzip2Ifstream ( const char *  filename)
explicit

Detailed constructor with filename.

◆ ~Bzip2Ifstream()

virtual ~Bzip2Ifstream ( )
virtual

Destructor.

◆ Bzip2Ifstream() [3/3]

Bzip2Ifstream ( const Bzip2Ifstream bzip2)
protected

Member Function Documentation

◆ close()

void close ( )

closes current file.

◆ isOpen()

bool isOpen ( ) const
inline

returns whether a file is open.

References Bzip2Ifstream::file_.

Referenced by Bzip2InputStream::getIsOpen().

◆ open()

void open ( const char *  filename)

opens a file for reading (decompression)

Note
any previous open files will be closed first!

◆ operator=()

Bzip2Ifstream& operator= ( const Bzip2Ifstream bzip2)
protected

◆ read()

size_t read ( char *  s,
size_t  n 
)

Reads n bytes from the bzip2 compressed file into buffer s.

Parameters
sBuffer to be filled with the output
nThe size of the buffer s
Returns
The number of actually read bytes. If it is less than n, the end of the file was reached and the stream is closed
Note
This returns a raw byte stream that is not null-terminated. Be careful here.
The length of the buffer needs to at least n
Closes the stream if the end of file is reached. Check isOpen before reading from the file again
Exceptions
Exception::ConversionErroris thrown if decompression fails
Exception::IllegalArgumentis thrown if no file for decompression is given. This can happen even happen if a file was already open but read until the end.

◆ streamEnd()

bool streamEnd ( ) const
inline

indicates whether the read function can be used safely

Returns
true if end of file was reached. Otherwise false.

References Bzip2Ifstream::stream_at_end_.

Member Data Documentation

◆ bzerror_

int bzerror_
protected

saves the last returned error by the read function

◆ bzip2file_

BZFILE* bzip2file_
protected

a pointer to a BZFILE object. Necessary for decompression

◆ file_

FILE* file_
protected

pointer to a FILE object. Necessary for opening the file

Referenced by Bzip2Ifstream::isOpen().

◆ n_buffer_

size_t n_buffer_
protected

counts the last read buffer

◆ stream_at_end_

bool stream_at_end_
protected

true if end of file is reached

Referenced by Bzip2Ifstream::streamEnd().