compressor.hpp
Go to the documentation of this file.
/*********************************************************************/
// dar - disk archive - a backup/restoration program
// Copyright (C) 2002-2023 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 COMPRESSOR_HPP
#define COMPRESSOR_HPP
#include "../my_config.h"
#include "infinint.hpp"
#include "integers.hpp"
#include "wrapperlib.hpp"
#include "proto_compressor.hpp"
namespace libdar
{
class compressor : public proto_compressor
{
public :
compressor(compression x_algo,
generic_file & compressed_side,
U_I compression_level = 9
);
compressor(const compressor & ref) = delete;
compressor(compressor && ref) noexcept = delete;
compressor & operator = (const compressor & ref) = delete;
compressor & operator = (compressor && ref) noexcept = delete;
virtual ~compressor();
// inherited from proto_compressor
virtual compression get_algo() const override;
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 { return compressed->skippable(direction, amount); };
virtual bool skip(const infinint & pos) override { inherited_sync_write(); inherited_flush_read(); return compressed->skip(pos); };
virtual bool skip_to_eof() override { inherited_sync_write(); inherited_flush_read(); return compressed->skip_to_eof(); };
virtual bool skip_relative(S_I x) override { inherited_sync_write(); inherited_flush_read(); return compressed->skip_relative(x); };
virtual bool truncatable(const infinint & pos) const override { return compressed->truncatable(pos); };
virtual infinint get_position() const override { if(compr != nullptr && compr->wrap.get_total_in() != 0) throw SRC_BUG; return compressed->get_position(); };
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;
virtual void inherited_terminate() override;
private :
struct xfer
{
wrapperlib wrap;
char *buffer;
U_I size;
xfer(U_I sz, wrapperlib_mode mode);
~xfer();
};
xfer *compr;
bool read_mode;
generic_file *compressed;
compression algo;
bool suspended;
void flush_write();
};
} // end of namespace
#endif
libdar::compressor
compression class for gzip and bzip2 algorithms
Definition: compressor.hpp:45
libdar::compressor::algo
compression algo
compression algorithm used
Definition: compressor.hpp:101
libdar::compressor::flush_write
void flush_write()
drop all pending write and reset compression engine
libdar::compressor::inherited_read_ahead
virtual void inherited_read_ahead(const infinint &amount) override
tells the object that several calls to read() will follow to probably obtain at least the given amoun...
Definition: compressor.hpp:79
libdar::compressor::compressed
generic_file * compressed
where to read from/write to compressed data
Definition: compressor.hpp:100
libdar::compressor::suspended
bool suspended
whether compression is temporary suspended
Definition: compressor.hpp:102
libdar::compressor::inherited_sync_write
virtual void inherited_sync_write() override
write down any pending data
libdar::compressor::read_mode
bool read_mode
read-only mode or write-only mode, read-write is write-only mode
Definition: compressor.hpp:99
libdar::compressor::compressor
compressor(const compressor &ref)=delete
libdar::compressor::inherited_truncate
virtual void inherited_truncate(const infinint &pos) override
truncate file at the give offset
libdar::compressor::get_position
virtual infinint get_position() const override
get the current read/write position
Definition: compressor.hpp:76
libdar::compressor::skippable
virtual bool skippable(skippability direction, const infinint &amount) override
whether the implementation is able to skip
Definition: compressor.hpp:71
libdar::compressor::inherited_write
virtual void inherited_write(const char *a, U_I size) override
implementation of the write() operation
libdar::compressor::skip_to_eof
virtual bool skip_to_eof() override
skip to the end of file
Definition: compressor.hpp:73
libdar::compressor::inherited_terminate
virtual void inherited_terminate() override
destructor-like call, except that it is allowed to throw exceptions
libdar::compressor::skip
virtual bool skip(const infinint &pos) override
skip at the absolute position
Definition: compressor.hpp:72
libdar::compressor::compressor
compressor(compression x_algo, generic_file &compressed_side, U_I compression_level=9)
libdar::compressor::truncatable
virtual bool truncatable(const infinint &pos) const override
whether the implementation is able to truncate to the given position
Definition: compressor.hpp:75
libdar::compressor::inherited_flush_read
virtual void inherited_flush_read() override
reset internal engine, flush caches in order to read the data at current position
libdar::compressor::inherited_read
virtual U_I inherited_read(char *a, U_I size) override
implementation of read() operation
libdar::compressor::skip_relative
virtual bool skip_relative(S_I x) override
skip relatively to the current position
Definition: compressor.hpp:74
libdar::compressor::compr
xfer * compr
datastructure for bzip2, gzip and zx compression (not use with compression::none
Definition: compressor.hpp:98
libdar::generic_file
this is the interface class from which all other data transfer classes inherit
Definition: generic_file.hpp:77
libdar::generic_file::truncatable
virtual bool truncatable(const infinint &pos) const =0
whether the implementation is able to truncate to the given position
libdar::generic_file::skip
virtual bool skip(const infinint &pos)=0
skip at the absolute position
libdar::generic_file::skippable
virtual bool skippable(skippability direction, const infinint &amount)=0
whether the implementation is able to skip
libdar::generic_file::read_ahead
void read_ahead(const infinint &amount)
libdar::generic_file::get_position
virtual infinint get_position() const =0
get the current read/write position
libdar::generic_file::skip_relative
virtual bool skip_relative(S_I x)=0
skip relatively to the current position
libdar::generic_file::skip_to_eof
virtual bool skip_to_eof()=0
skip to the end of file
libdar::infinint
the arbitrary large positive integer class
Definition: real_infinint.hpp:62
libdar::wrapperlib
this class encapsulates calls to libz or libbz2
Definition: wrapperlib.hpp:75
libdar::compression
compression
the different compression algorithm available
Definition: compression.hpp:46
infinint.hpp
switch module to limitint (32 ou 64 bits integers) or infinint
integers.hpp
are defined here basic integer types that tend to be portable
libdar
libdar namespace encapsulate all libdar symbols
Definition: archive.hpp:47
proto_compressor.hpp
abstracted ancestor class for compressor and parallel_compressor classes
wrapperlib.hpp
libz and libbz2 wrapper to have identical interface to these libraries.