34 #ifndef SPARSE_FILE_HPP
35 #define SPARSE_FILE_HPP
37 #include "../my_config.h"
49 #define SPARSE_FIXED_ZEROED_BLOCK 40960
51 #if SSIZE_MAX < MAX_BUFFER_SIZE
52 #undef MAX_BUFFER_SIZE
53 #define SPARSE_FIXED_ZEROED_BLOCK SSIZE_MAX
63 class sparse_file :
public escape
71 sparse_file(generic_file *below,
const infinint & hole_size = 15);
72 sparse_file(
const sparse_file & ref) =
default;
73 sparse_file(sparse_file && ref) noexcept =
default;
74 sparse_file & operator = (
const sparse_file & ref) =
default;
75 sparse_file & operator = (sparse_file && ref) noexcept =
default;
76 ~sparse_file() =
default;
81 void write_as_escape(
bool mode) { escape_write = mode; };
86 void read_as_escape(
bool mode) { escape_read = mode; };
91 void copy_to_without_skip(
bool mode) { copy_to_no_skip = mode; };
93 bool has_seen_hole()
const {
return seen_hole; };
94 bool has_escaped_data()
const {
return data_escaped; };
107 virtual void copy_to(generic_file & ref)
override { crc *tmp =
nullptr;
copy_to(ref, 0, tmp);
if(tmp !=
nullptr)
throw SRC_BUG; };
112 virtual void copy_to(generic_file & ref,
const infinint & crc_size, crc * & value)
override;
115 virtual bool skippable(skippability direction,
const infinint & amount)
override {
return false; };
116 virtual bool skip(
const infinint & pos)
override {
if(pos != offset)
throw Efeature(
"skip in sparse_file");
else return true; };
117 virtual bool skip_to_eof()
override {
throw Efeature(
"skip in sparse_file"); };
118 virtual bool skip_relative(S_I x)
override {
if(x != 0)
throw Efeature(
"skip in sparse_file");
return true; };
119 virtual infinint get_position()
const override;
125 void add_mark_at_current_position(sequence_type t) { escape::add_mark_at_current_position(t); };
126 bool skip_to_next_mark(sequence_type t,
bool jump) {
return escape::skip_to_next_mark(t, jump); };
127 bool next_to_read_is_mark(sequence_type t) {
return escape::next_to_read_is_mark(t); };
128 void add_unjumpable_mark(sequence_type t) { escape::add_unjumpable_mark(t); };
132 virtual U_I inherited_read(
char *a, U_I size)
override;
133 virtual void inherited_write(
const char *a, U_I size)
override;
134 virtual void inherited_sync_write()
override;
139 static bool initialized;
140 static unsigned char zeroed_field[SPARSE_FIXED_ZEROED_BLOCK];
142 enum { normal, hole } mode;
145 infinint min_hole_size;
146 U_I UI_min_hole_size;
149 bool copy_to_no_skip;
155 void dump_pending_zeros();
158 void write_hole(
const infinint & length);
175 static bool look_for_hole(
const char *a, U_I size, U_I min_hole_size, U_I & start, U_I & length);
182 static U_I count_initial_zeros(
const char *a, U_I size);
U_32 copy_to(generic_file &ref, U_32 size)
small copy (up to 4GB) with CRC calculation
class escape definition, used for sequential reading of archives
class generic_file is defined here as well as class fichier
libdar namespace encapsulate all libdar symbols