OnRead callback function:

You can use the OnRead parameter to specify a callback procedure when you make the DwinsHs_ReadRemoteURL function call. The callback procedure will be executed when a data block is read by the DwinsHs_ReadRemoteURL function.

Declaration:

type
  TReadMethod = (rmGet, rmPost, rmActive, rmPassive);
  #ifdef UNICODE// For UNICODE Inno Setup
  TOnRead = function (URL, Agent: AnsiString; Method: TReadMethod;
    Index, TotalSize, ReadSize, CurrentSize: Int64; var ReadStr: AnsiString): Boolean;
  #else // For ANSI Inno Setup
  TOnRead = function (URL, Agent: AnsiString; Method: TReadMethod;
    Index, TotalSize, ReadSize, CurrentSize: LongInt; var ReadStr: AnsiString): Boolean;
  #endif

Parameters:

Return:

Returns true to continue to download the remote file. Retunrs false to terminate the download operation, the DwinsHs_ReadRemoteURL function will return immediately, and the error code READ_ERROR_CANCELED (9) will be returned by it.

Examples:

You can use the callback procedure to save the remote file:

var
  Response: AnsiString;
  Size: {#BIG_INT};
...
function OnRead(URL, Agent: AnsiString; Method: TReadMethod; Index, TotalSize, ReadSize,
  CurrentSize: {#BIG_INT}; varReadStr: AnsiString): Boolean;
begin
  if Index = 0 then
    // Create local file and write first data block
    SaveStringToFile( ExpandConstant('{tmp}/local_filename'), ReadStr, False )
  else
    // Append subsequent data blocks to the local file
    SaveStringToFile( ExpandConstant('{tmp}/local_filename'), ReadStr, Ture );
  ReadStr := ''; // Optional, change to empty string for freeing up memory space
  Result := True; // Continue to download
end;
...
DwinsHs_ReadRemoteURL('http://.....', 'My_Setup', rmGet, Response, Size, '', @OnRead);

The callback function can be used to update the progress indicator, for example:

var
  ProgressBar: TNewProgressBar;
  Response: AnsiString;
  Size: {#BIG_INT};
...
function OnRead(URL, Agent: AnsiString; Method: TReadMethod; Index, TotalSize, ReadSize,
  CurrentSize: {#BIG_INT}; varReadStr: AnsiString): Boolean;
begin
  ProgressBar.Position := (ReadSize div TotalSize) * 100;
  Result := True;
end;
...
ProgressBar := TNewProgressBar.Create(...);
ProgressBar.Min := 0;
ProgressBar.Max := 100;
ProgressBar.Position := 0;
DwinsHs_ReadRemoteURL('http://.....', 'My_Setup', rmGet, Response, Size,
  ExpandConstant('{tmp}/local_filename'), @OnRead);

It can be used to encrypt or decrypt file content or response text too, for example:

var
  Response: AnsiString;
  Size: {#BIG_INT};
...
function OnRead(URL, Agent: AnsiString; Method: TReadMethod; Index, TotalSize, ReadSize,
  CurrentSize: {#BIG_INT}; varReadStr: AnsiString): Boolean;
var
  i: Integer;
begin
  // Simple to encrype the file content
  for i := 1 to ReadSize do ReadStr[i] := Chr(Ord(ReadStr[i]) xor $55);
  Result := True;
end;
...
if DwinsHs_ReadRemoteURL( 'http://.....', 'My_Setup', rmGet, Response, Size, '', @OnReaded )
      = READ_OK then
  SaveStringToFile( ExpandConstant('{tmp}/local_filename'), Response, False );

Also, it can be used to check whether the user terminates the download operation, for example:

var
  Response: AnsiString;
  Size: {#BIG_INT};
  Canceled: Boolean;
...
function BackButtonClick(CurPageID: Integer): Boolean;
begin
  Result := True;
  // Terminates download operation when user clicks on the "Back" button
  Canceled := True;
end;
...
function OnReaded(URL, Agent: AnsiString; Method: TReadMethod; Index, TotalSize, ReadSize,
  CurrentSize: {#BIG_INT}; varReadedStr: AnsiString): Boolean;
begin
  Result := not Canceled;
end;
...
Canceled := False;
DwinsHs_ReadRemoteURL('http://.....', 'My_Setup', rmGet, Response, Size,
  ExpandConstant('{tmp}/local_filename'), @OnReaded);
...