Implements AWS S3 compatible CRC64-NVME checksum calculation. Pure Elixir implementation with no external dependencies.
CRC64 is a 64-bit cyclic redundancy check algorithm used for error detection. This implementation uses the polynomial 0x9A6C9329AC4BC9B5 which is compatible with AWS S3's CRC64 implementation.
Installation
Available in Hex, the package can be installed
by adding crc_64 to your list of dependencies in mix.exs:
def deps do
[
{:crc_64, "~> 0.1.0"}
]
endUsage
Calculate CRC64 Checksum (as integer)
# Calculate checksum for a binary
checksum = Crc64.calculate("Hello, world!")
# Returns a non-negative integerCalculate CRC64 Checksum (as Base64 string)
# Calculate Base64-encoded checksum
base64_checksum = Crc64.calculate_base64("Hello, world!")
# Returns a Base64 string like "Ik7A4/gH+LE="Validate Data against Checksum
# Check if data matches a checksum
data = "Important content"
checksum = "dGhlIGNoZWNrc3VtIGhlcmU=" # previously calculated Base64 checksum
is_valid = Crc64.valid_checksum?(data, checksum)
# Returns true if the calculated checksum matchesValidate File against Checksum
# Validate a file against a known checksum
file_path = "path/to/your/file.txt"
checksum = "dGhlIGNoZWNrc3VtIGhlcmU=" # previously calculated Base64 checksum
is_valid = Crc64.valid_file_checksum?(file_path, checksum)
# Returns true if the file's checksum matchesDocumentation can be found at https://hexdocs.pm/crc_64.