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

Decompresses gzip or bzip2 data read from another InputStream, e.g. a remote object. More...

#include <OpenMS/FORMAT/DecompressingInputStream.h>

Inheritance diagram for DecompressingInputStream:
InputStream

Public Types

enum class  Format { GZIP , BZIP2 }
 

Public Member Functions

 DecompressingInputStream (std::unique_ptr< InputStream > source, Format format, const std::string &name)
 Decompresses source, which holds data in format.
 
 ~DecompressingInputStream () override
 
UInt64 curPos () const override
 The number of decompressed bytes read so far.
 
Size readBytes (unsigned char *to_fill, Size max_to_read) override
 Reads up to max_to_read decompressed bytes into to_fill; 0 at the end of the data.
 
void cancel () override
 Cancels a blocking read of the source stream.
 
 DecompressingInputStream (const DecompressingInputStream &)=delete
 
DecompressingInputStream & operator= (const DecompressingInputStream &)=delete
 
- Public Member Functions inherited from InputStream
virtual ~InputStream ()=default
 

Static Public Member Functions

static std::optional< Format > detect (const unsigned char *head, Size size)
 The format whose magic bytes start head (1F 8B: gzip, "BZh": bzip2), if any.
 

Private Attributes

std::unique_ptr< Impl > impl_
 zlib/bzip2 state (their headers stay out of this one)
 

Detailed Description

Decompresses gzip or bzip2 data read from another InputStream, e.g. a remote object.

Unlike GzipInputStream and Bzip2InputStream, which open local files, this decompresses an arbitrary stream on the fly. Concatenated members (as written by pigz or pbzip2) are read in sequence. Bytes after the last member that do not start another member are ignored, as gzread() does.

Errors of the source stream propagate. Corrupt or truncated compressed data throws Exception::ParseError.

Member Enumeration Documentation

◆ Format

enum class Format
strong
Enumerator
GZIP 
BZIP2 

Constructor & Destructor Documentation

◆ DecompressingInputStream() [1/2]

DecompressingInputStream ( std::unique_ptr< InputStream >  source,
Format  format,
const std::string &  name 
)

Decompresses source, which holds data in format.

Parameters
[in]sourceThe compressed stream; it is read from its current position
[in]formatThe compression format of source
[in]nameThe name of the data, for error messages (e.g. its URI)

◆ ~DecompressingInputStream()

~DecompressingInputStream ( )
override

◆ DecompressingInputStream() [2/2]

Member Function Documentation

◆ cancel()

void cancel ( )
overridevirtual

Cancels a blocking read of the source stream.

Reimplemented from InputStream.

◆ curPos()

UInt64 curPos ( ) const
overridevirtual

The number of decompressed bytes read so far.

Implements InputStream.

◆ detect()

static std::optional< Format > detect ( const unsigned char *  head,
Size  size 
)
static

The format whose magic bytes start head (1F 8B: gzip, "BZh": bzip2), if any.

◆ operator=()

DecompressingInputStream & operator= ( const DecompressingInputStream &  )
delete

◆ readBytes()

Size readBytes ( unsigned char *  to_fill,
Size  max_to_read 
)
overridevirtual

Reads up to max_to_read decompressed bytes into to_fill; 0 at the end of the data.

Implements InputStream.

Member Data Documentation

◆ impl_

std::unique_ptr<Impl> impl_
private

zlib/bzip2 state (their headers stay out of this one)