37 #ifndef SPARSE_FILE_HPP
38 #define SPARSE_FILE_HPP
40 #include "../my_config.h"
56 #define SPARSE_FIXED_ZEROED_BLOCK 40960
58 #if SSIZE_MAX < MAX_BUFFER_SIZE
59 #undef MAX_BUFFER_SIZE
60 #define SPARSE_FIXED_ZEROED_BLOCK SSIZE_MAX
68 class sparse_file :
public escape
76 sparse_file(generic_file *below,
const infinint & hole_size = 15);
78 void write_as_escape(
bool mode) { escape_write = mode; };
79 void read_as_escape(
bool mode) { escape_read = mode; };
80 void copy_to_without_skip(
bool mode) { copy_to_no_skip = mode; };
82 bool has_seen_hole()
const {
return seen_hole; };
83 bool has_escaped_data()
const {
return data_escaped; };
95 void copy_to(generic_file & ref) { crc value = infinint(1);
copy_to(ref, value); };
98 void copy_to(generic_file & ref, crc & value);
102 bool skip(
const infinint & pos) {
if(pos != offset)
throw Efeature(
"skip in sparse_file");
else return true; };
103 bool skip_to_eof() {
throw Efeature(
"skip in sparse_file"); };
104 bool skip_relative(S_I x) {
if(x != 0)
throw Efeature(
"skip in sparse_file");
return true; };
105 infinint get_position();
111 void add_mark_at_current_position(sequence_type t) { escape::add_mark_at_current_position(t); };
112 bool skip_to_next_mark(sequence_type t,
bool jump) {
return escape::skip_to_next_mark(t, jump); };
113 bool next_to_read_is_mark(sequence_type t) {
return escape::next_to_read_is_mark(t); };
114 void add_unjumpable_mark(sequence_type t) { escape::add_unjumpable_mark(t); };
118 U_I inherited_read(
char *a, U_I size);
119 void inherited_write(
const char *a, U_I size);
120 void inherited_sync_write();
121 void inherited_terminate() { escape::inherited_terminate(); };
124 static bool initialized;
125 static unsigned char zeroed_field[SPARSE_FIXED_ZEROED_BLOCK];
127 enum { normal, hole } mode;
130 infinint min_hole_size;
131 U_I UI_min_hole_size;
134 bool copy_to_no_skip;
140 void dump_pending_zeros();
143 void write_hole(
const infinint & length);
154 static bool look_for_hole(
const char *a, U_I size, U_I min_hole_size, U_I & start, U_I & length);
161 static U_I count_initial_zeros(
const char *a, U_I size);