Skip to content

Commit

Permalink
Todo done: GetCRC32File now use a TBufferedFileStream instead of bloc…
Browse files Browse the repository at this point in the history
…k file reading
  • Loading branch information
Pozitronik authored and Pozitronik committed May 21, 2019
1 parent 4c73457 commit 0043f8e
Showing 1 changed file with 7 additions and 9 deletions.
16 changes: 7 additions & 9 deletions SplitFile.pas
Original file line number Diff line number Diff line change
Expand Up @@ -127,26 +127,24 @@ destructor TFileSplitInfo.Destroy;
inherited;
end;

function TFileSplitInfo.GetCRC32File(filename: WideString = ''): WideString;
function TFileSplitInfo.GetCRC32File(filename: WideString): WideString;
var
inFile: file;
CRCValue: DWord;
inbuffer: array [1 .. 32768] of Byte;
ReadBytes: Integer;
begin //todo: change to TFileStream (just for code sameness
Stream: TBufferedFileStream;
begin
if EmptyWideStr = filename then
filename := self.filename;

AssignFile(inFile, filename);
FileMode := fmOpenRead or fmShareDenyWrite;
Reset(inFile, 1);
Stream := TBufferedFileStream.Create(filename, fmOpenRead or fmShareDenyWrite);
CRCValue := CRCSeed;
blockread(inFile, inbuffer, Sizeof(inbuffer), ReadBytes);
ReadBytes := Stream.Read(inbuffer, Sizeof(inbuffer));
repeat
CRCValue := crc32_update(@inbuffer, ReadBytes, CRCValue);
blockread(inFile, inbuffer, Sizeof(inbuffer), ReadBytes);
ReadBytes := Stream.Read(inbuffer, Sizeof(inbuffer));
until ReadBytes = 0;
CloseFile(inFile);
Stream.Destroy;
CRCValue := CRCend(CRCValue);
exit(IntToHex(CRCValue, 8));
end;
Expand Down

0 comments on commit 0043f8e

Please sign in to comment.