On this page

    M

    zlib.crc32c

    History
    zlib.crc32c(data, value?): integer
    Attributes
    When data is a string, it will be encoded as UTF-8 before being used for computation.
    value?:integer
    An optional starting value. It must be a 32-bit unsigned integer. Default: 0
    Returns:integer
    A 32-bit unsigned integer containing the checksum.

    Computes a 32-bit Cyclic Redundancy Check checksum of data using the Castagnoli polynomial (CRC-32C, RFC 3720 section 12.1). If value is specified, it is used as the starting value of the checksum, otherwise, 0 is used as the starting value. Passing the result of a previous call as value continues the checksum, as with zlib.crc32().

    CRC-32C is a different checksum from the CRC-32 computed by zlib.crc32(); the two produce different results for the same input. CRC-32C is used by protocols and formats such as iSCSI, SCTP, ext4, Btrfs, and the Snappy framing format, and has better error detection properties than CRC-32.

    The CRC algorithm is designed to compute checksums and to detect error in data transmission. It's not suitable for cryptographic authentication.

    Strings are encoded as UTF-8, in the same way as zlib.crc32().

    import zlib from 'node:zlib';
    
    let crc = zlib.crc32c('hello');  // 2591144780
    crc = zlib.crc32c('world', crc);  // 1456190592
    const zlib = require('node:zlib');
    
    let crc = zlib.crc32c('hello');  // 2591144780
    crc = zlib.crc32c('world', crc);  // 1456190592