Add crc32()

This commit is contained in:
josh committed 2023-10-09 19:06:51 -04:00
1 parent 9f39cddc24
commit 42e2508766
1 file changed
+18
+18
View File
@@ -0,0 +1,18 @@
module fart.crc32;
import std.digest.crc;
/**
* Calculate the CRC32 across the given chunk(s) of data.
*/
public uint crc32(Args...)(Args data)
{
CRC32 crc32;
crc32.start();
static foreach (arg; data)
{
crc32.put(cast(const(ubyte)[])arg);
}
auto crc = crc32.finish();
return crc[0] | (crc[1] << 8) | (crc[2] << 16) | (crc[3] << 24);
}