calculate static method

int calculate(
  1. dynamic input, [
  2. int crc = 0
])

Calculate a CRC32 value for the given input.

The return value is an unsigned integer.

You may optionally specify the beginning CRC value.

Implementation

static int calculate(var input, [int crc = 0]) {
  if (input == null) throw ArgumentError.notNull('input');
  if (input is String) input = utf8.encode(input);

  crc = crc ^ (0xffffffff);

  for (var byte in input) {
    if (!(byte >= -128 && byte <= 255)) {
      throw FormatException("Invalid value in input: $byte");
    }

    var x = Crc32._haxListTable[(crc ^ byte) & 0xff];
    crc = (crc & 0xffffffff) >> 8; // crc >>> 8 (32-bit unsigned integer)
    crc ^= x;
  }

  crc = crc ^ (0xffffffff);

  // Turns the signed integer into an unsigned integer.
  return crc & 0xffffffff;
}