lua-zlib icon indicating copy to clipboard operation
lua-zlib copied to clipboard

add checksum functions and tobinary functions

Open starwing opened this issue 14 years ago • 2 comments

  • port crc32 and adler32 functions to lua.
  • add a function convert int32 checksum to string.

starwing avatar Oct 10 '11 03:10 starwing

Okay, I have added the documents and test cases, and remove the tobinary function :)

starwing avatar Oct 11 '11 07:10 starwing

Sorry for being slow on the uptake here... after thinking about this a bit, I'm proposing a function factory interface that more closely mirrors the compression interface:

https://github.com/brimworks/lua-zlib/commit/f94aabf944581df865e70b7943962fa18c9d0838

Specifically you can do this:

        -- All in one call:
        local csum = zlib.crc32()("one two")

        -- Multiple calls:
        local compute = zlib.crc32()
        compute("one")
        assert(csum == compute(" two"))

        -- Multiple compute_checksums joined:
        local compute1, compute2 = zlib.crc32(), zlib.crc32()
        compute1("one")
        compute2(" two")
        assert(csum == compute1(compute2))

Feedback is welcomed.

brimworks avatar May 12 '13 04:05 brimworks