Disk ARchive  2.7.14
Full featured and portable backup and archiving tool
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;
102  bool suspended;
103 
104  void flush_write();
105  };
106 
108 
109 } // end of namespace
110 
111 #endif
are defined here basic integer types that tend to be portable
virtual infinint get_position() const override
get the current read/write position
Definition: compressor.hpp:76
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
virtual void inherited_sync_write() override
write down any pending data
virtual bool truncatable(const infinint &pos) const =0
whether the implementation is able to truncate to the given position
virtual bool skip(const infinint &pos)=0
skip at the absolute position
virtual bool skip_relative(S_I x)=0
skip relatively to the current position
void read_ahead(const infinint &amount)
void flush_write()
drop all pending write and reset compression engine
bool suspended
whether compression is temporary suspended
Definition: compressor.hpp:102
abstracted ancestor class for compressor and parallel_compressor classes
xfer * compr
datastructure for bzip2, gzip and zx compression (not use with compression::none
Definition: compressor.hpp:98
compression algo
compression algorithm used
Definition: compressor.hpp:101
virtual void inherited_terminate() override
destructor-like call, except that it is allowed to throw exceptions
libz and libbz2 wrapper to have identical interface to these libraries.libz and libbz2 library differ...
this class encapsulates calls to libz or libbz2
Definition: wrapperlib.hpp:74
virtual bool skippable(skippability direction, const infinint &amount) override
whether the implementation is able to skip
Definition: compressor.hpp:71
switch module to limitint (32 ou 64 bits integers) or infinint
compression class for gzip and bzip2 algorithms
Definition: compressor.hpp:44
virtual bool skip(const infinint &pos) override
skip at the absolute position
Definition: compressor.hpp:72
virtual void inherited_flush_read() override
reset internal engine, flush caches in order to read the data at current position ...
virtual bool skip_to_eof() override
skip to the end of file
Definition: compressor.hpp:73
compressor(compression x_algo, generic_file &compressed_side, U_I compression_level=9)
virtual infinint get_position() const =0
get the current read/write position
compression
the different compression algorithm available
Definition: compression.hpp:45
this is the interface class from which all other data transfer classes inherit
virtual void inherited_truncate(const infinint &pos) override
truncate file at the give offset
the arbitrary large positive integer class
virtual bool truncatable(const infinint &pos) const override
whether the implementation is able to truncate to the given position
Definition: compressor.hpp:75
generic_file * compressed
where to read from/write to compressed data
Definition: compressor.hpp:100
virtual bool skip_relative(S_I x) override
skip relatively to the current position
Definition: compressor.hpp:74
virtual U_I inherited_read(char *a, U_I size) override
implementation of read() operation
virtual bool skip_to_eof()=0
skip to the end of file
virtual void inherited_write(const char *a, U_I size) override
implementation of the write() operation
libdar namespace encapsulate all libdar symbols
Definition: archive.hpp:46
virtual bool skippable(skippability direction, const infinint &amount)=0
whether the implementation is able to skip
bool read_mode
read-only mode or write-only mode, read-write is write-only mode
Definition: compressor.hpp:99