112 {
116 }
117
118 long remaining = loc;
119
120
121 file.seek_end(-expected_seek_point_count_size);
122 seek_point_count_type seek_point_count = 0;
123 file.read(reinterpret_cast<char*>(&seek_point_count), sizeof(seek_point_count));
124
125 if (seek_point_count > 0) {
126 int seek_map_size = sizeof(seek_point_entry) * seek_point_count;
127 file.seek_end(-expected_seek_point_count_size - seek_map_size);
128
129 std::vector<seek_point_entry> seek_point_map(seek_point_count);
130 file.read(reinterpret_cast<char*>(seek_point_map.data()), seek_point_map.size() * sizeof(seek_point_entry));
131
132
133 auto iter = std::lower_bound(seek_point_map.begin(), seek_point_map.end(), (
uint64_t)loc, [](
const auto& lhs,
const auto& rhs ){
134 return std::get<0>(lhs) < rhs;
135 });
136
137
138 if ( iter != seek_point_map.end() && std::get<0>(*iter) == loc ) {
139 file.seek(std::get<1>(*iter));
140 return;
141 }
142
143
144 if ( iter == seek_point_map.begin() ) {
145 file.seek(0);
146 } else {
147
148 const auto& seek_pt = *(iter - 1);
149 file.seek(std::get<1>(seek_pt));
150 remaining -= std::get<0>(seek_pt);
151 }
152 } else {
153 file.seek(0);
154 }
155
156
157 if (remaining > 0) {
158 auto pre_read_buffer = std::vector<char>(remaining);
159 read(pre_read_buffer.data(), pre_read_buffer.size(), file);
160 }
161 }
unsigned __int64 uint64_t
void read(char *d, size_t n, fc::cfile &file)