AvogadroLibs 2.1.0-20261111
Loading...
Searching...
No Matches
DecompressingStreamBuf Class Reference

A stream buffer that decompresses another stream on demand. More...

#include <compressedstream.h>

Inheritance diagram for DecompressingStreamBuf:

Public Member Functions

 DecompressingStreamBuf (std::unique_ptr< std::istream > source, Compression type, std::uint64_t maxDecodedSize=defaultMaxDecompressedSize)
 Wrap source, which must be positioned at the first byte.
 DecompressingStreamBuf (const DecompressingStreamBuf &)=delete
DecompressingStreamBuf & operator= (const DecompressingStreamBuf &)=delete
std::string error () const
 The error encountered while decoding, if any.
bool hitSizeLimit () const
std::uint64_t decodedSize () const

Protected Member Functions

int_type underflow () override
std::streamsize xsgetn (char *s, std::streamsize count) override
pos_type seekoff (off_type off, std::ios_base::seekdir dir, std::ios_base::openmode which=std::ios_base::in|std::ios_base::out) override
pos_type seekpos (pos_type pos, std::ios_base::openmode which=std::ios_base::in|std::ios_base::out) override

Detailed Description

<avogadro/io/compressedstream.h>

Decoded bytes are produced lazily, a block at a time, and every block is retained, so the buffer is seekable in both directions even though the underlying codecs are not. Seeking forward decodes as far as the target; seeking to the end decodes everything. That matters because several readers measure a file by seeking to its end (DCD and TRR take block lengths from the file itself) and others rewind to re-read a record (MDL, Molden), so they would not work against a forward only stream.

The cost is memory: a reader that seeks to the end of a compressed trajectory holds the whole decompressed trajectory. That is what the size limit is for.

Constructor & Destructor Documentation

◆ DecompressingStreamBuf()

DecompressingStreamBuf ( std::unique_ptr< std::istream > source,
Compression type,
std::uint64_t maxDecodedSize = defaultMaxDecompressedSize )
Parameters
sourceThe compressed stream. Ownership is taken, and it is read incrementally rather than all at once.
typeThe codec, as determined by detectCompression().
maxDecodedSizeThe ceiling on decoded bytes; 0 means no ceiling.

Member Function Documentation

◆ error()

std::string error ( ) const

Empty while all is well. A truncated file, a failed integrity check or a breach of the size limit all leave a message here. Callers must check this after reading, because a decoding failure surfaces to the reader as an ordinary end of stream, which most parsers treat as a short but valid file.

◆ hitSizeLimit()

bool hitSizeLimit ( ) const
Returns
True if decoding stopped because the size limit was reached.

◆ decodedSize()

std::uint64_t decodedSize ( ) const
Returns
The number of bytes decoded so far.

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