getCrc32 function

int getCrc32 (
  1. List<int> array,
  2. [int crc = 0]
)

Get the CRC-32 checksum of the given array. You can append bytes to an already computed crc by specifying the previous crc value.

Implementation

int getCrc32(List<int> array, [int crc = 0]) {
  var len = array.length;
  crc = crc ^ 0xffffffff;
  var ip = 0;
  while (len >= 8) {
    crc = _CRC32_TABLE[(crc ^ array[ip++]) & 0xff] ^ (crc >> 8);
    crc = _CRC32_TABLE[(crc ^ array[ip++]) & 0xff] ^ (crc >> 8);
    crc = _CRC32_TABLE[(crc ^ array[ip++]) & 0xff] ^ (crc >> 8);
    crc = _CRC32_TABLE[(crc ^ array[ip++]) & 0xff] ^ (crc >> 8);
    crc = _CRC32_TABLE[(crc ^ array[ip++]) & 0xff] ^ (crc >> 8);
    crc = _CRC32_TABLE[(crc ^ array[ip++]) & 0xff] ^ (crc >> 8);
    crc = _CRC32_TABLE[(crc ^ array[ip++]) & 0xff] ^ (crc >> 8);
    crc = _CRC32_TABLE[(crc ^ array[ip++]) & 0xff] ^ (crc >> 8);
    len -= 8;
  }
  if (len > 0) {
    do {
      crc = _CRC32_TABLE[(crc ^ array[ip++]) & 0xff] ^ (crc >> 8);
    } while (--len > 0);
  }
  return crc ^ 0xffffffff;
}