The Crc32 class is a utility designed to compute CRC32 checksums for various types of input data. CRC32 (Cyclic Redundancy Check) is a common error-detection code used in network communications, file storage, and other applications where data integrity verification is essential.

Methods

  • Computes the CRC32 checksum of the given binary data.

    Parameters

    • data: Uint8Array

      The binary data for which the checksum will be computed.

    Returns number

    The computed CRC32 checksum as a 32-bit integer.

    const binaryData = new Uint8Array([0x01, 0x02, 0x03]);
    const checksum = Crc32.compute(binaryData);
    console.log(checksum); // Outputs the checksum as a number
  • Computes the CRC32 checksum of a hexadecimal string.

    The method converts the hexadecimal string into binary data before computing the checksum.

    Parameters

    • hexString: string

      The hexadecimal string to process.

    Returns number

    The computed CRC32 checksum as a 32-bit integer.

    const hexString = "010203";
    const checksum = Crc32.computeFromHex(hexString);
    console.log(checksum); // Outputs the checksum as a number
  • Computes the CRC32 checksum of a UTF-8 encoded string.

    The method first encodes the string as UTF-8 binary data and then computes the checksum.

    Parameters

    • data: string

      The UTF-8 string to process.

    Returns number

    The computed CRC32 checksum as a 32-bit integer.

    const utf8String = "Hello, World!";
    const checksum = Crc32.computeFromUtf8(utf8String);
    console.log(checksum); // Outputs the checksum as a number