libabigail
Public Member Functions | Protected Member Functions | List of all members
xz_decompressor_type Class Reference

This is a custom std::streambuf that knows how to decompress an input stream that was compressed using xz. More...

#include <abg-tools-utils.h>

Inheritance diagram for xz_decompressor_type:
[legend]

Public Member Functions

 xz_decompressor_type (std::istream &xz_istream)
 Constructor of the xz_decompressor_type class. More...
 
 ~xz_decompressor_type ()
 Destructor of the xz_decompressor_type class. More...
 

Protected Member Functions

int_type underflow () override
 The implementation of the virtual protected std:streambuf::underflow method. This method is invoked by the std::streambuf facility to re-fill its internals buffers with data coming from the associated input stream and to update the gptr() and egptr() pointers by using the std::streambuf::setg method. More...
 

Detailed Description

This is a custom std::streambuf that knows how to decompress an input stream that was compressed using xz.

The code was inspired by the example in the source code of the xz project at https://github.com/tukaani-project/xz/blob/master/doc/examples/02_decompress.c.

here is an example of how a user code would use this custom streambuf to decode an xz'ed file and emit its content to stdout.

ifstream input_file("/path/to/a/compressed/file.xz", ifstream::binary); xz_decompressor_type xzed_streambuf(input_file); istream input_stream(&xzed_streambuf);

const size_t BUFFER_SIZE = 1024 * 4; vector<char> decompressed_data(BUFFER_SIZE); input_stream.read(decompressed_data.data(), BUFFER_SIZE); size_t nb_bytes_read = input_stream.gcount(); while (nb_bytes_read && !input_stream.bad()) { for (auto c : decompressed_data) std::out << c; input_stream.read(decompressed_data.data(), BUFFER_SIZE); nb_bytes_read = input_stream.gcount(); } input_file.close();

Voila.

Definition at line 425 of file abg-tools-utils.h.

Constructor & Destructor Documentation

xz_decompressor_type ( std::istream &  xz_istream)

Constructor of the xz_decompressor_type class.

Parameters
xz_istreamthe input stream containing the xz-compressed data to decompress.

Definition at line 3582 of file abg-tools-utils.cc.

Destructor of the xz_decompressor_type class.

Definition at line 3593 of file abg-tools-utils.cc.

Member Function Documentation

std::streambuf::int_type underflow ( )
overrideprotected

The implementation of the virtual protected std:streambuf::underflow method. This method is invoked by the std::streambuf facility to re-fill its internals buffers with data coming from the associated input stream and to update the gptr() and egptr() pointers by using the std::streambuf::setg method.

This is where the decompression using the lzma library is performed.

Definition at line 3607 of file abg-tools-utils.cc.


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