19 int64_t old_position = file.get_position();
20 file.set_position(start);
22 constexpr uint32_t chunks = 2048;
25 int64_t current_size = 0;
30 if (current_size + int64_t(block_size) > size)
31 block_size = size_t(size - current_size);
33 const size_t read_count = file.read_data(&hashing_buffer[0], block_size);
34 current_size += int64_t(read_count);
36 for (uint32_t i = 0; i < full_chunks; i++)
40 if (remainder || current_size >= size || read_count == 0)
45 uint64_t(current_size)
51 file.set_position(old_position);
80 constexpr int buffer_count = 256;
82 if (size < 4 * file.buffer.ssize * buffer_count)
83 return get_hash(file, start, size);
86 const int64_t old_position = file.get_position();
89 for (
int i = 0; i < buffer_count; i++)
91 int64_t buffer_position;
94 buffer_position = start;
95 else if (i == buffer_count - 1)
96 buffer_position = start + size - file.buffer.ssize;
99 buffer_position = file.buffer.ssize *
101 (start + i * size) / (file.buffer.ssize * (buffer_count - 1))
105 file.pread(file.buffer.data, file.buffer.size, buffer_position);
111 file.set_position(old_position);
virtual int64_t get_size() const
Get the size of the file, or -1 if it is unknown.
static SHA_256::Hash get_fast_hash(Buffered_File &file, int64_t start, int64_t size)
static SHA_256::Hash get_hash(Buffered_File &file, int64_t start, int64_t size)
static SHA_256::Hash get_full_hash(const Readonly_Journal &journal, int64_t checkpoint)
static SHA_256::Hash get_fast_hash(const Readonly_Journal &journal, int64_t checkpoint)
const Hash & get_hash() const
void process_chunk(const char *data)
process 512 bits (32 * 16, 8 * 64) of data, SHA_256::chunk_size bytes
std::array< uint32_t, 8 > Hash
static constexpr size_t chunk_size
void process_final_chunk(const char *const data, const uint64_t total_length_in_bytes)
process last bytes of the sequence