19 constexpr uint32_t chunks = 2048;
22 int64_t current = from;
27 if (current + int64_t(block_size) > until)
28 block_size = size_t(until - current);
30 file.full_pread(hashing_buffer.data(), block_size, current);
31 current += int64_t(block_size);
33 for (uint32_t i = 0; i < full_chunks; i++)
37 if (remainder || current >= until)
42 uint64_t(current - from)
75 std::array<char, 1 << 12> buffer;
77 constexpr int buffer_count = 256;
78 const int64_t size = until - from;
80 if (size < 4 * int64_t(buffer.size()) * buffer_count)
85 for (
int i = 0; i < buffer_count; i++)
87 int64_t buffer_position;
90 buffer_position = from;
91 else if (i == buffer_count - 1)
92 buffer_position = until - int64_t(buffer.size());
95 buffer_position = int64_t(buffer.size()) *
97 (from + (i * size) / (buffer_count - 1)) / int64_t(buffer.size())
101 file.full_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.
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
SHA_256::Hash get_full_hash(const Abstract_File &file, int64_t from, int64_t until)
SHA_256::Hash get_fast_hash(const Abstract_File &file, int64_t from, int64_t until)