A library for working with phylogenetic and population genetic data.
v0.32.0
GzipIFStream Class Reference

#include <genesis/utils/io/gzip_stream.hpp>

Inherits StrictFStreamHolder< StrictIFStream >, and istream.

Detailed Description

Input file stream that offers on-the-fly gzip-decompression if needed.

The class accesses an internal std::ifstream. This can be used to open a file and read decompressed data from it.

If auto_detect is true (default), the class seamlessly auto-detects whether the source stream is compressed or not. The following compressed streams are detected:

  • GZip header, when stream starts with 1F 8B. See GZip format.
  • ZLib header, when stream starts with 78 01, 78 9C, or 78 DA. See answer here.

If none of these formats are detected, the class assumes the input is not compressed, and it produces a plain copy of the source stream. In order to fully work for compressed files however, we always use std::ios_base::binary for opening. This means that on Windows, end-of-line chars are not properly converted for uncompressed files. See https://github.com/mateidavid/zstr/issues/15 for a workaround for this, for example by using our is_gzip_compressed_file() function before opening the file.

The class is based on the zstr::ifstream class of the excellent zstr library by Matei David; see also our Acknowledgements.

If genesis is compiled without zlib support, constructing an instance of this class will throw an exception.

See also
GzipIStream
GzipOStream
GzipOFStream

Definition at line 276 of file gzip_stream.hpp.

Public Member Functions

 GzipIFStream (std::string const &filename, std::ios_base::openmode mode=std::ios_base::in, bool auto_detect=true, std::size_t buffer_size=GZIP_DEFAULT_BUFFER_SIZE)
 
virtual ~GzipIFStream ()
 

Constructor & Destructor Documentation

◆ GzipIFStream()

GzipIFStream ( std::string const &  filename,
std::ios_base::openmode  mode = std::ios_base::in,
bool  auto_detect = true,
std::size_t  buffer_size = GZIP_DEFAULT_BUFFER_SIZE 
)
explicit

Definition at line 539 of file gzip_stream.cpp.

◆ ~GzipIFStream()

~GzipIFStream ( )
virtual

Definition at line 554 of file gzip_stream.cpp.


The documentation for this class was generated from the following files: