Skip to content

Latest commit

 

History

History
36 lines (24 loc) · 1.26 KB

TPJMD5-CalculateFile.md

File metadata and controls

36 lines (24 loc) · 1.26 KB

CalculateFile method

Project: MD5 Message Digest Unit

Unit: PJMD5

Class: TPJMD5

Applies to: ~>1.0

class function CalculateFile(const FileName: TFileName): TPJMD5Digest;

Description

This class method is very like the Calculate methods in that it provides a useful shortcut when you want to get the MD5 hash of a single file. Just call this method and pass the path to the required file in the FileName parameter and read the function result to get the required digest.

Like Calculate, there is no need to create an instance of TPJMD5 to use this method.

The disadvantage of this method over the similar ProcessFile method is that there is no way to change the default size of the buffer used to read the file. The buffer size is that given by the TPJMD5.DefReadBufferSize constant.

Example

Here's how to check if the MD5 hashes of two files are the same:

function SameMD5(const FileName1, FileName2: TFileName): Boolean;
var
  D1, D2: TPJMD5Digest;
begin
  D1 := TPJMD5.CalculateFile(FileName1);
  D2 := TPJMD5.CalculateFile(FileName2);
  Result := D1 = D2;
end;