Disk ARchive 2.7.16
Full featured and portable backup and archiving tool
Loading...
Searching...
No Matches
block_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
27#ifndef BLOCK_COMPRESSOR_HPP
28#define BLOCK_COMPRESSOR_HPP
29
30#include "../my_config.h"
31
32#include "infinint.hpp"
33#include "crypto_segment.hpp"
34#include "heap.hpp"
35#include "compress_module.hpp"
36#include "proto_compressor.hpp"
37
38namespace libdar
39{
40
43
44
45 class block_compressor: public proto_compressor
46 {
47 public:
48 block_compressor(std::unique_ptr<compress_module> block_zipper,
49 generic_file & compressed_side,
50 U_I uncompressed_bs = default_uncompressed_block_size);
51 // compressed_side is not owned by the object and will remains
52 // after the objet destruction
53
54 block_compressor(const block_compressor & ref) = delete;
55 block_compressor(block_compressor && ref) noexcept = delete;
56 block_compressor & operator = (const block_compressor & ref) = delete;
57 block_compressor & operator = (block_compressor && ref) noexcept = delete;
58 ~block_compressor();
59
60 // inherited from proto_compressor
61
62 virtual compression get_algo() const override { return suspended? compression::none : zipper->get_algo(); };
63 virtual void suspend_compression() override;
64 virtual void resume_compression() override;
65 virtual bool is_compression_suspended() const override { return suspended; };
66
67 // inherited from generic file
68
69 virtual bool skippable(skippability direction, const infinint & amount) override;
70 virtual bool skip(const infinint & pos) override;
71 virtual bool skip_to_eof() override;
72 virtual bool skip_relative(S_I x) override;
73 virtual bool truncatable(const infinint & pos) const override;
74 virtual infinint get_position() const override;
75
76 protected :
77 virtual void inherited_read_ahead(const infinint & amount) override { compressed->read_ahead(amount); };
78 virtual U_I inherited_read(char *a, U_I size) override;
79 virtual void inherited_write(const char *a, U_I size) override;
80 virtual void inherited_truncate(const infinint & pos) override;
81 virtual void inherited_sync_write() override;
82 virtual void inherited_flush_read() override { if(get_mode() != gf_write_only) current->reset(); reof = false; };
83 virtual void inherited_terminate() override;
84
85 private:
86 static constexpr const U_I min_uncompressed_block_size = 100;
87
88
89 // the local fields
90
91 std::unique_ptr<compress_module> zipper;
92 generic_file *compressed;
93 U_I uncompressed_block_size;
94 bool suspended;
95 bool need_eof;
96 std::unique_ptr<crypto_segment> current;
97 bool reof;
98
99 // private methods
100
101 void compress_and_write_current();
102 void read_and_uncompress_current();
103
104 };
105
107
108} // end of namespace
109
110
111#endif
void read_ahead(const infinint &amount)
gf_mode get_mode() const
retreive the openning mode for this object
provides abstracted interface of per-block compression/decompression
defines unit block of information ciphered as once
@ none
no compression
@ gf_write_only
write only access
Definition gf_mode.hpp:46
heap data structure (relying on FIFO)
switch module to limitint (32 ou 64 bits integers) or infinint
include macro defined by the configure script and some specific additional ones
libdar namespace encapsulate all libdar symbols
Definition archive.hpp:47
abstracted ancestor class for compressor and parallel_compressor classes