Loading...
Searching...
No Matches
compressor_zstd.hpp
Go to the documentation of this file.
/*********************************************************************/
// dar - disk archive - a backup/restoration program
// Copyright (C) 2002-2025 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_ZSTD_HPP
#define COMPRESSOR_ZSTD_HPP
#include "../my_config.h"
extern "C"
{
#if HAVE_ZSTD_H
#include <zstd.h>
#endif
}
#include "proto_compressor.hpp"
namespace libdar
{
class compressor_zstd : public proto_compressor
{
public :
compressor_zstd(generic_file & compressed_side, U_I compression_level = 9);
// compressed_side is not owned by the object and will remains
// after the objet destruction
compressor_zstd(const compressor_zstd & ref) = delete;
compressor_zstd(compressor_zstd && ref) noexcept = delete;
compressor_zstd & operator = (const compressor_zstd & ref) = delete;
compressor_zstd & operator = (compressor_zstd && ref) noexcept = delete;
~compressor_zstd();
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 { compr_flush_write(); compr_flush_read(); clean_read(); return compressed->skip(pos); };
virtual bool skip_to_eof() override { compr_flush_write(); compr_flush_read(); clean_read(); return compressed->skip_to_eof(); };
virtual bool skip_relative(S_I x) override { compr_flush_write(); compr_flush_read(); clean_read(); return compressed->skip_relative(x); };
virtual bool truncatable(const infinint & pos) const override { return compressed->truncatable(pos); };
virtual infinint get_position() const override { 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 { compr_flush_write(); };
virtual void inherited_flush_read() override { compr_flush_read(); clean_read(); };
virtual void inherited_terminate() override;
private :
generic_file *compressed;
bool suspended;
#if LIBZSTD_AVAILABLE
ZSTD_CStream *comp;
ZSTD_DStream *decomp;
ZSTD_inBuffer inbuf;
ZSTD_outBuffer outbuf;
char *below_tampon;
U_I below_tampon_size;
U_I above_tampon_size;
bool flueof;
bool no_comp_data;
#endif
void reset_compr_engine();
void compr_flush_write(); // flush all data to compressed_side, and reset the compressor_zstd
// for that additional write can be uncompresssed starting at this point.
void compr_flush_read(); // reset decompression engine to be able to read the next block of compressed data
// if not called, furthur read return EOF
void clean_read(); // discard any byte buffered and not yet returned by read()
void clean_write(); // discard any byte buffered and not yet wrote to compressed_side;
void clear_inbuf();
void clear_outbuf();
void release_mem();
void setup_context(U_I compression_level);
};
} // end of namespace
#endif
libdar::compressor_zstd
compression class for zstd algorithms
Definition compressor_zstd.hpp:50
libdar::compressor_zstd::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_zstd.hpp:78
libdar::compressor_zstd::reset_compr_engine
void reset_compr_engine()
reset the compression engine ready for use
libdar::compressor_zstd::inherited_read
virtual U_I inherited_read(char *a, U_I size) override
implementation of read() operation
libdar::compressor_zstd::inherited_flush_read
virtual void inherited_flush_read() override
reset internal engine, flush caches in order to read the data at current position
Definition compressor_zstd.hpp:83
libdar::compressor_zstd::skippable
virtual bool skippable(skippability direction, const infinint &amount) override
whether the implementation is able to skip
Definition compressor_zstd.hpp:70
libdar::compressor_zstd::skip_to_eof
virtual bool skip_to_eof() override
skip to the end of file
Definition compressor_zstd.hpp:72
libdar::compressor_zstd::skip
virtual bool skip(const infinint &pos) override
skip at the absolute position
Definition compressor_zstd.hpp:71
libdar::compressor_zstd::inherited_write
virtual void inherited_write(const char *a, U_I size) override
implementation of the write() operation
libdar::compressor_zstd::clear_inbuf
void clear_inbuf()
from zstd
libdar::compressor_zstd::skip_relative
virtual bool skip_relative(S_I x) override
skip relatively to the current position
Definition compressor_zstd.hpp:73
libdar::compressor_zstd::inherited_terminate
virtual void inherited_terminate() override
destructor-like call, except that it is allowed to throw exceptions
libdar::compressor_zstd::inherited_truncate
virtual void inherited_truncate(const infinint &pos) override
truncate file at the give offset
libdar::compressor_zstd::inherited_sync_write
virtual void inherited_sync_write() override
write down any pending data
Definition compressor_zstd.hpp:82
libdar::compressor_zstd::truncatable
virtual bool truncatable(const infinint &pos) const override
whether the implementation is able to truncate to the given position
Definition compressor_zstd.hpp:74
libdar::compressor_zstd::get_position
virtual infinint get_position() const override
get the current read/write position
Definition compressor_zstd.hpp:75
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::compression
compression
the different compression algorithm available
Definition compression.hpp:46
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