chunkLogicalLength function
Logical length of chunk index for a file of logicalLength bytes.
This is the number of bytes the chunk contributes to the logical file
(chunkSize for every chunk except a partial trailing one).
Implementation
int chunkLogicalLength(int index, int chunkSize, int logicalLength) {
final start = chunkStartFor(index, chunkSize);
if (start >= logicalLength) return 0;
final remaining = logicalLength - start;
return remaining < chunkSize ? remaining : chunkSize;
}