34 #ifndef SPARSE_FILE_HPP
35 #define SPARSE_FILE_HPP
37 #include "../my_config.h"
53 #define SPARSE_FIXED_ZEROED_BLOCK 40960
55 #if SSIZE_MAX < MAX_BUFFER_SIZE
56 #undef MAX_BUFFER_SIZE
57 #define SPARSE_FIXED_ZEROED_BLOCK SSIZE_MAX
65 class sparse_file :
public escape
73 sparse_file(generic_file *below,
const infinint & hole_size = 15);
75 void write_as_escape(
bool mode) { escape_write = mode; };
76 void read_as_escape(
bool mode) { escape_read = mode; };
77 void copy_to_without_skip(
bool mode) { copy_to_no_skip = mode; };
79 bool has_seen_hole()
const {
return seen_hole; };
80 bool has_escaped_data()
const {
return data_escaped; };
92 void copy_to(generic_file & ref) { crc *tmp =
nullptr;
copy_to(ref, 0, tmp);
if(tmp !=
nullptr)
throw SRC_BUG; };
95 void copy_to(generic_file & ref,
const infinint & crc_size, crc * & value);
98 bool skippable(skippability direction,
const infinint & amount) {
return false; };
99 bool skip(
const infinint & pos) {
if(pos != offset)
throw Efeature(
"skip in sparse_file");
else return true; };
100 bool skip_to_eof() {
throw Efeature(
"skip in sparse_file"); };
101 bool skip_relative(S_I x) {
if(x != 0)
throw Efeature(
"skip in sparse_file");
return true; };
102 infinint get_position()
const;
108 void add_mark_at_current_position(sequence_type t) { escape::add_mark_at_current_position(t); };
109 bool skip_to_next_mark(sequence_type t,
bool jump) {
return escape::skip_to_next_mark(t, jump); };
110 bool next_to_read_is_mark(sequence_type t) {
return escape::next_to_read_is_mark(t); };
111 void add_unjumpable_mark(sequence_type t) { escape::add_unjumpable_mark(t); };
115 U_I inherited_read(
char *a, U_I size);
116 void inherited_write(
const char *a, U_I size);
117 void inherited_sync_write();
122 static bool initialized;
123 static unsigned char zeroed_field[SPARSE_FIXED_ZEROED_BLOCK];
125 enum { normal, hole } mode;
128 infinint min_hole_size;
129 U_I UI_min_hole_size;
132 bool copy_to_no_skip;
138 void dump_pending_zeros();
141 void write_hole(
const infinint & length);
158 static bool look_for_hole(
const char *a, U_I size, U_I min_hole_size, U_I & start, U_I & length);
165 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 generic_file is defined here as well as class fichierthe generic_file interface is widely used ...
class escape definition, used for sequential reading of archivesThe class escape is used to insert es...