This algorithm provides CRC32 functions to Lua following the CRC-32/ISO-HDLC standard. Made purely in C.
Chaining / streaming supported. Tested in Lua 5.4.
Requires gcc and lua5.x to be available via pkg-config.
makeThis will produce crc32.so in the project directory.
Place crc32.so into your project's directory, then require it in Lua:
local crc32 = require( "crc32" )
local nChecksum
nChecksum = crc32.compute( "Test" )
nChecksum = crc32.compute( "String", nChecksum ) -- Chaining is optional.
print( nChecksum ) -- Prints the checksum for "TestString".Computes a CRC32 checksum with chaining support, allowing data to be fed in chunks if init is provided.
| Parameter | Type | Default | Description |
|---|---|---|---|
input |
string |
— | The chunk of data to process. |
init |
number |
0 |
The previous checksum, for chaining calls. |
Returns: number — The CRC32 checksum.
Computes a CRC32 checksum of a file by reading it in buffered chunks.
| Parameter | Type | Description |
|---|---|---|
filename |
string |
Path to the file to checksum. |
Returns: number — The CRC32 checksum.
On my system, average throughput is above 2 GB/s.
Here's a sample on a 3GB file:
ryan@cherry:~/Git/GitHub/crc32-lua-c$ lua tests/filethroughput.lua
Creating test file...
Generating checksum...
Checksum: 2005293256
Duration: 1.321096 seconds
Throughput: 2325 MB/second