Skip to content

Latest commit

 

History

History
40 lines (29 loc) · 1.22 KB

TPJMD5-ProcessFile.md

File metadata and controls

40 lines (29 loc) · 1.22 KB

ProcessFile method

Project: MD5 Message Digest Unit

Unit: PJMD5

Class: TPJMD5

Applies to: ~>1.0

procedure ProcessFile(const FileName: TFileName);

Description

This class method is very like the Process methods in that it adds data to the current hash. In this case the method reads the file named by the FileName parameter and adds the bytes representing the whole of the file to the current hash.

The file is read into an internal buffer before adding the data to the hash. The buffer's size can be changed by assigning the required size to the TPJMD5.ReadBufferSize property. Find the current size of the buffer by reading the property.

Example

Suppose you want a single MD5 hash of all the files in a directory. If the required file names are stored in a string list then the following function will find the required MD5 hash:

function MD5OfFiles(const FileNames: TStrings): TPJMD5Digest;
var
  FileName: string;
  MD5: TPJMD5;
begin
  MD5 := TPJMD5.Create;
  try
    for FileName in FileNames do
      MD5.ProcessFile(FileName);
    Result := MD5.Digest;
  finally
    MD5.Free;
  end;
end;