| Disk ARchive 2.7.14 Full featured and portable backup and archiving tool

Loading...
Searching...
No Matches
compressor.hpp
Go to the documentation of this file.
1/*********************************************************************/
2// dar - disk archive - a backup/restoration program
3// Copyright (C) 2002-2024 Denis Corbin
4//
5// This program is free software; you can redistribute it and/or
6// modify it under the terms of the GNU General Public License
7// as published by the Free Software Foundation; either version 2
8// of the License, or (at your option) any later version.
9//
10// This program is distributed in the hope that it will be useful,
11// but WITHOUT ANY WARRANTY; without even the implied warranty of
12// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13// GNU General Public License for more details.
14//
15// You should have received a copy of the GNU General Public License
16// along with this program; if not, write to the Free Software
17// Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
18//
19// to contact the author, see the AUTHOR file
20/*********************************************************************/
21
25
26#ifndef COMPRESSOR_HPP
27#define COMPRESSOR_HPP
28
29#include "../my_config.h"
30
31#include "infinint.hpp"
32#include "integers.hpp"
33#include "wrapperlib.hpp"
34#include "proto_compressor.hpp"
35
36 namespace libdar
37{
38
39
42
44 class compressor : public proto_compressor
45 {
46 public :
47 compressor(compression x_algo,
48 generic_file & compressed_side,
49 U_I compression_level = 9
50 );
53
54 compressor(const compressor & ref) = delete;
55 compressor(compressor && ref) noexcept = delete;
56 compressor & operator = (const compressor & ref) = delete;
57 compressor & operator = (compressor && ref) noexcept = delete;
58 virtual ~compressor();
59
60
61 // inherited from proto_compressor
62
63 virtual compression get_algo() const override;
64 virtual void suspend_compression() override;
65 virtual void resume_compression() override;
66 virtual bool is_compression_suspended() const override { return suspended; };
67
68
69 // inherited from generic file
70
71 virtual bool skippable(skippability direction, const infinint & amount) override { return compressed->skippable(direction, amount); };
72 virtual bool skip(const infinint & pos) override { inherited_sync_write(); inherited_flush_read(); return compressed->skip(pos); };
73 virtual bool skip_to_eof() override { inherited_sync_write(); inherited_flush_read(); return compressed->skip_to_eof(); };
74 virtual bool skip_relative(S_I x) override { inherited_sync_write(); inherited_flush_read(); return compressed->skip_relative(x); };
75 virtual bool truncatable(const infinint & pos) const override { return compressed->truncatable(pos); };
76 virtual infinint get_position() const override { if(compr != nullptr && compr->wrap.get_total_in() != 0) throw SRC_BUG; return compressed->get_position(); };
77
78 protected :
79 virtual void inherited_read_ahead(const infinint & amount) override { compressed->read_ahead(amount); };
80 virtual U_I inherited_read(char *a, U_I size) override;
81 virtual void inherited_write(const char *a, U_I size) override;
82 virtual void inherited_truncate(const infinint & pos) override;
83 virtual void inherited_sync_write() override;
84 virtual void inherited_flush_read() override;
85 virtual void inherited_terminate() override;
86
87 private :
88 struct xfer
89 {
90 wrapperlib wrap;
91 char *buffer;
92 U_I size;
93
94 xfer(U_I sz, wrapperlib_mode mode);
95 ~xfer();
96 };
97
98 xfer *compr;
99 bool read_mode;
100 generic_file *compressed;
101 compression algo;
102 bool suspended;
103
104 void flush_write();
105 };
106
108
109} // end of namespace
110
111#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.