Skip to content

GlorifiedPig/crc32-lua-c

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

18 Commits
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

CRC32 Lua C Bindings

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.

Building

Requires gcc and lua5.x to be available via pkg-config.

make

This will produce crc32.so in the project directory.

Usage

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".

Documentation


crc32.compute( input, init[optional] )

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.


crc32.streamfile( filename )

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.


Performance

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

About

C module for Lua CRC32 bindings

Topics

Resources

Stars

Watchers

Forks

Contributors