fourdgsCrc32Range function

Future<int> fourdgsCrc32Range(
  1. FourdgsReadable source,
  2. int start,
  3. int length
)

The checksum of [start, start + length) of source, a block at a time.

The Footer names a byte range, and a caller that has to hold the whole range to check it is a caller that reads a file to check a file (AGENTS.md ยง1). CRC-32 is a running state, so a region is checked block by block with nothing but a 32-bit accumulator resident.

Implementation

Future<int> fourdgsCrc32Range(
  FourdgsReadable source,
  int start,
  int length,
) async {
  int crc = 0;
  int at = start;
  final int end = start + length;
  while (at < end) {
    final int take =
        end - at < fourdgsCrcBlockBytes ? end - at : fourdgsCrcBlockBytes;
    crc = fourdgsCrc32(await source.read(at, take), crc);
    at += take;
  }
  return crc;
}