Welcome to the new DelphiDabbler Code Library Documentation.

This is a new site that's currently running on alpha code. There are going to be bugs. If you discover any, please report them on the site's issues page (GitHub account required). Thanks.

Warning: Many URLs are going to change. Refer to the README file to discover which library project's documentation has been completed.

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;