FileCRC function

This commit is contained in:
mysticbbs 2012-08-11 12:49:10 -04:00
parent d38e0740c5
commit 1211cdf7fc
1 changed files with 28 additions and 3 deletions

View File

@ -27,8 +27,9 @@ Unit m_CRC;
Interface Interface
Function Crc16 (CP: Byte; CRC: Word) : Word; Function Crc16 (CP: Byte; CRC: Word) : Word;
Function Crc32 (Octet: Byte; CRC: LongInt) : LongInt; Function Crc32 (Octet: Byte; CRC: LongInt) : LongInt;
Function FileCRC32 (FileName: String) : LongInt;
Implementation Implementation
@ -111,7 +112,31 @@ Const
Function Crc32 (Octet: Byte; CRC: LongInt) : LongInt; Function Crc32 (Octet: Byte; CRC: LongInt) : LongInt;
Begin Begin
Crc32 := CRC_32_TAB[Byte(CRC xor LongInt(Octet))] xor ((CRC shr 8) and $00FFFFFF); Crc32 := LongInt(CRC_32_TAB[Byte(CRC xor LongInt(Octet))] xor ((CRC shr 8) and $00FFFFFF));
End;
Function FileCRC32 (FileName: String) : LongInt;
Var
InFile : File;
Buffer : Array[1..1024*8] of Byte;
BufSize : SmallInt;
Count : SmallInt;
Begin
Result := LongInt($FFFFFFFF);
Assign (InFile, FileName);
Reset (InFile, 1);
If IoResult <> 0 Then Exit;
While Not Eof(InFile) Do Begin
BlockRead (InFile, Buffer, SizeOf(Buffer), BufSize);
For Count := 1 to Bufsize Do
Result := Crc32(Buffer[Count], Result);
End;
Close (InFile);
End; End;
End. End.