Loading...
Searching...
No Matches
block_compressor.hpp
Go to the documentation of this file.
/*********************************************************************/
// dar - disk archive - a backup/restoration program
// Copyright (C) 2002-2024 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::get_mode
gf_mode get_mode() const
retreive the openning mode for this object
Definition generic_file.hpp:109
compress_module.hpp
provides abstracted interface of per-block compression/decompression
crypto_segment.hpp
defines unit block of information ciphered as once
libdar::compression
compression
the different compression algorithm available
Definition compression.hpp:46
libdar::compression::none
@ none
no compression
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
libdar
libdar namespace encapsulate all libdar symbols
Definition archive.hpp:47
proto_compressor.hpp
abstracted ancestor class for compressor and parallel_compressor classes