Add update-crc version for crc32 function with Data argument

This commit is contained in:
Timofey Solomko
2017-07-29 23:28:33 +03:00
parent 559c47a42d
commit b1bc89ecdd
+2 -2
View File
@@ -18,8 +18,8 @@ struct CheckSums {
return ~crc
}
static func crc32(_ data: Data) -> UInt32 {
var crc: UInt32 = ~0
static func crc32(_ data: Data, prevValue: UInt32 = 0) -> UInt32 {
var crc = ~prevValue
for i in 0..<data.count {
let index = (crc & 0xFF) ^ (UInt32(data[i]))
crc = CheckSums.crc32table[Int(index)] ^ (crc >> 8)