|
AvogadroLibs 2.1.0-20261111
|
A stream buffer that decompresses another stream on demand. More...
#include <compressedstream.h>
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 |
<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.
| DecompressingStreamBuf | ( | std::unique_ptr< std::istream > | source, |
| Compression | type, | ||
| std::uint64_t | maxDecodedSize = defaultMaxDecompressedSize ) |
| source | The compressed stream. Ownership is taken, and it is read incrementally rather than all at once. |
| type | The codec, as determined by detectCompression(). |
| maxDecodedSize | The ceiling on decoded bytes; 0 means no ceiling. |
| 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.
| bool hitSizeLimit | ( | ) | const |
| std::uint64_t decodedSize | ( | ) | const |