Popularity
6 Stars
Updated Last
1 Year Ago
Started In
December 2022

CI codecov

CRC32

CRC32 is a Julia package for computing the CRC-32 checksum as defined by the ISO 3309 / ITU-T V.42 / CRC-32-IEEE standards, designed as a drop-in replacement for Julia's CRC32c standard library (which computes the CRC-32c checksum). A wider variety of CRC checksum algorithms is provided by the CRC.jl package, and cryptographic checksums can be found in MD5.jl and SHA.jl.

It exports a single function, crc32, described below (analogous to CRC32c.crc32c).

The implementation uses the crc32 function in the zlib library by Mark Adler and others.

Although zlib's CRC-32 implementation is highly optimized, it is still typically slower than the CRC32c.crc32c function of the Julia standard library (which is also based on code by Mark Adler), because CRC-32c checksums benefit from greater hardware acceleration on typical CPUs. The main motivation for this package is for validating data from external sources that only provide a CRC-32 checksum.

crc32(data, [crc]) and crc32(io, [crc]):

crc32(data, crc::UInt32=0x00000000)

Computes the CRC-32 checksum (ISO 3309, ITU-T V.42, CRC-32-IEEE) of the given data, which can be an Array{UInt8}, a contiguous subarray thereof, or a String. Optionally, you can pass a starting crc integer to be mixed in with the checksum. The crc parameter can be used to compute a checksum on data divided into chunks: performing crc32(data2, crc32(data1)) is equivalent to the checksum of [data1; data2].

There is also a method crc32(io, nb, crc) to checksum nb bytes from a stream io, or crc32(io, crc) to checksum all the remaining bytes. Hence you can do open(crc32, filename) to checksum an entire file, or crc32(seekstart(buf)) to checksum an IOBuffer without calling take!.

For a String, note that the result is specific to the UTF-8 encoding (a different checksum would be obtained from a different Unicode encoding).

Authors

Steven G. Johnson, based on API code from the Julia CRC32c standard library (also originally contributed by SGJ). The crc32 function in zlib was developed by Mark Adler.

The Julia code in this package (and its antecedents in the Julia CRC32c standard library) is free/open-source software under the MIT License (see LICENSE file). Zlib is free/open-source software under a similar license.