OpenMS
Loading...
Searching...
No Matches
ZipIfstream Class Reference

Decompresses a single-entry ZIP archive for streaming reading. More...

#include <OpenMS/FORMAT/ZipIfstream.h>

Collaboration diagram for ZipIfstream:
[legend]

Public Member Functions

 ZipIfstream ()
 Default Constructor.
 
 ZipIfstream (const char *filename)
 Detailed constructor with filename.
 
virtual ~ZipIfstream ()
 Destructor.
 
size_t read (char *s, size_t n)
 Reads n bytes from the zip entry into buffer s.
 
bool streamEnd () const
 indicates whether the read function can be used safely
 
bool isOpen () const
 returns whether a file is open.
 
void open (const char *filename)
 opens a ZIP archive for reading from its single non-directory entry
 
void close ()
 closes current file.
 
 ZipIfstream (const ZipIfstream &)=delete
 
ZipIfstreamoperator= (const ZipIfstream &)=delete
 
 ZipIfstream (ZipIfstream &&)=delete
 
ZipIfstreamoperator= (ZipIfstream &&)=delete
 

Protected Attributes

void * zip_archive_ = nullptr
 opaque pointers to libzip handles (void* to avoid including zip.h in header)
 
void * zip_entry_ = nullptr
 
bool stream_at_end_ = true
 true if end of entry is reached
 

Detailed Description

Decompresses a single-entry ZIP archive for streaming reading.

Wraps libzip to stream bytes from the single non-directory entry in a ZIP file. Directory entries (names ending with '/') are silently skipped. Exactly one non-directory entry must be present; otherwise open() throws.

Constructor & Destructor Documentation

◆ ZipIfstream() [1/4]

Default Constructor.

◆ ZipIfstream() [2/4]

ZipIfstream ( const char *  filename)
explicit

Detailed constructor with filename.

◆ ~ZipIfstream()

virtual ~ZipIfstream ( )
virtual

Destructor.

◆ ZipIfstream() [3/4]

ZipIfstream ( const ZipIfstream )
delete

◆ ZipIfstream() [4/4]

ZipIfstream ( ZipIfstream &&  )
delete

Member Function Documentation

◆ close()

void close ( )

closes current file.

◆ isOpen()

bool isOpen ( ) const
inline

returns whether a file is open.

References ZipIfstream::zip_entry_.

◆ open()

void open ( const char *  filename)

opens a ZIP archive for reading from its single non-directory entry

Note
any previous open files will be closed first!
Exceptions
Exception::FileNotFoundif file does not exist
Exception::FileNotReadableif file cannot be opened
Exception::FileEmptyif ZIP contains no non-directory entries
Exception::ParseErrorif ZIP contains more than one non-directory entry

◆ operator=() [1/2]

ZipIfstream & operator= ( const ZipIfstream )
delete

◆ operator=() [2/2]

ZipIfstream & operator= ( ZipIfstream &&  )
delete

◆ read()

size_t read ( char *  s,
size_t  n 
)

Reads n bytes from the zip entry into buffer s.

Parameters
[out]sBuffer to be filled with the output
[in]nThe size of the buffer s
Returns
The number of actually read bytes. If it is less than n, the end of the entry was reached and the stream is closed.
Exceptions
Exception::ParseErroris thrown if decompression fails
Exception::IllegalArgumentis thrown if no file for decompression is given

◆ streamEnd()

bool streamEnd ( ) const
inline

indicates whether the read function can be used safely

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

References ZipIfstream::stream_at_end_.

Member Data Documentation

◆ stream_at_end_

bool stream_at_end_ = true
protected

true if end of entry is reached

Referenced by ZipIfstream::streamEnd().

◆ zip_archive_

void* zip_archive_ = nullptr
protected

opaque pointers to libzip handles (void* to avoid including zip.h in header)

◆ zip_entry_

void* zip_entry_ = nullptr
protected

Referenced by ZipIfstream::isOpen().