Loading...
Searching...
No Matches
block_compressor.hpp
Go to the documentation of this file.
/*********************************************************************/
// dar - disk archive - a backup/restoration program
// Copyright (C) 2002-2026 Denis Corbin
//
// This program is free software; you can redistribute it and/or
// modify it under the terms of the GNU General Public License
// as published by the Free Software Foundation; either version 2
// of the License, or (at your option) any later version.
//
// This program is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with this program; if not, write to the Free Software
// Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
//
// to contact the author, see the AUTHOR file
/*********************************************************************/
#ifndef BLOCK_COMPRESSOR_HPP
#define BLOCK_COMPRESSOR_HPP
#include "../my_config.h"
#include "infinint.hpp"
#include "crypto_segment.hpp"
#include "heap.hpp"
#include "compress_module.hpp"
#include "proto_compressor.hpp"
namespace libdar
{
class block_compressor: public proto_compressor
{
public:
block_compressor(std::unique_ptr<compress_module> block_zipper,
generic_file & compressed_side,
U_I uncompressed_bs = default_uncompressed_block_size);
// compressed_side is not owned by the object and will remains
// after the objet destruction
block_compressor(const block_compressor & ref) = delete;
block_compressor(block_compressor && ref) noexcept = delete;
block_compressor & operator = (const block_compressor & ref) = delete;
block_compressor & operator = (block_compressor && ref) noexcept = delete;
~block_compressor();
// inherited from proto_compressor
virtual compression get_algo() const override { return suspended? compression::none : zipper->get_algo(); };
virtual void suspend_compression() override;
virtual void resume_compression() override;
virtual bool is_compression_suspended() const override { return suspended; };
// inherited from generic file
virtual bool skippable(skippability direction, const infinint & amount) override;
virtual bool skip(const infinint & pos) override;
virtual bool skip_to_eof() override;
virtual bool skip_relative(S_I x) override;
virtual bool truncatable(const infinint & pos) const override;
virtual infinint get_position() const override;
protected :
virtual void inherited_read_ahead(const infinint & amount) override { compressed->read_ahead(amount); };
virtual U_I inherited_read(char *a, U_I size) override;
virtual void inherited_write(const char *a, U_I size) override;
virtual void inherited_truncate(const infinint & pos) override;
virtual void inherited_sync_write() override;
virtual void inherited_flush_read() override { if(get_mode() != gf_write_only) current->reset(); reof = false; };
virtual void inherited_terminate() override;
private:
static constexpr const U_I min_uncompressed_block_size = 100;
// the local fields
std::unique_ptr<compress_module> zipper;
generic_file *compressed;
U_I uncompressed_block_size;
bool suspended;
bool need_eof;
std::unique_ptr<crypto_segment> current;
bool reof;
// private methods
void compress_and_write_current();
void read_and_uncompress_current();
};
} // end of namespace
#endif
libdar::generic_file::inherited_sync_write
virtual void inherited_sync_write()=0
write down any pending data
libdar::generic_file::generic_file
generic_file(gf_mode m)
main constructor
Definition generic_file.hpp:80
libdar::generic_file::get_position
virtual infinint get_position() const =0
get the current read/write position
libdar::generic_file::skip_to_eof
virtual bool skip_to_eof()=0
skip to the end of file
libdar::generic_file::get_mode
gf_mode get_mode() const
retreive the openning mode for this object
Definition generic_file.hpp:109
libdar::generic_file::inherited_terminate
virtual void inherited_terminate()=0
destructor-like call, except that it is allowed to throw exceptions
libdar::generic_file::inherited_flush_read
virtual void inherited_flush_read()=0
reset internal engine, flush caches in order to read the data at current position
compress_module.hpp
provides abstracted interface of per-block compression/decompression
crypto_segment.hpp
defines unit block of information ciphered at once
libdar::compression
compression
the different compression algorithm available
Definition compression.hpp:46
libdar::compression::none
@ none
no compression
Definition compression.hpp:47
libdar::gf_write_only
@ gf_write_only
write only access
Definition gf_mode.hpp:46
heap.hpp
heap data structure (relying on FIFO)
infinint.hpp
switch module to limitint (32 ou 64 bits integers) or infinint
my_config.h
include macro defined by the configure script and some specific additional ones
libdar
libdar namespace encapsulate all libdar symbols
Definition archive.hpp:47
proto_compressor.hpp
abstracted ancestor class for compressor and parallel_compressor classes