20 constexpr uint32_t chunks = 2048;
23 int64_t current_size = 0;
28 if (current_size + int64_t(block_size) > size)
29 block_size = size_t(size - current_size);
31 const size_t read_count = file.pread(hashing_buffer.data(), block_size, start + current_size);
32 current_size += int64_t(read_count);
34 for (uint32_t i = 0; i < full_chunks; i++)
38 if (remainder || current_size >= size || read_count == 0)
43 uint64_t(current_size)
76 std::array<char, 1 << 12> buffer;
78 constexpr int buffer_count = 256;
80 if (size < 4 * int64_t(buffer.size()) * buffer_count)
81 return get_hash(file, start, size);
85 for (
int i = 0; i < buffer_count; i++)
87 int64_t buffer_position;
90 buffer_position = start;
91 else if (i == buffer_count - 1)
92 buffer_position = start + size - int64_t(buffer.size());
95 buffer_position = int64_t(buffer.size()) *
97 (start + i * size) / (int64_t(buffer.size()) * (buffer_count - 1))
101 file.pread(buffer.data(), buffer.size(), buffer_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(const Abstract_File &file, int64_t start, int64_t size)
static SHA_256::Hash get_hash(const Abstract_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)
Compute SHA 256 hash code: https://en.wikipedia.org/wiki/SHA-2.
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
static constexpr size_t chunk_size
std::array< uint32_t, 8 > Hash
void process_final_chunk(const char *const data, const uint64_t total_length_in_bytes)
process last bytes of the sequence