Other than that maybe you could just add a little modification to the
HTTPSend class to work with TFileStream instead then you can avoid all that
mess.
On 15 April 2017 at 01:28, brian - <hikarito...@gmail.com> wrote:
> You will need to work with the Status event, capturing data read and then
> deciding a threshold to flush the buffer to a file and clear it
>
> I made a custom class/wrapper for this
>
> Type
> TOnReceiveData = procedure(Len,Max: Int64) of object;
>
> Var
> DownloadSize: Int64;
> xOnReceiveData: TOnReceiveData;
>
> Type TSynHTTP = class(TObject)
>
> Sock.OnStatus := Status;
>
> //Callback function for status events
> procedure TSynHTTP.Status(Sender: TObject; Reason: THookSocketReason;
> const Value: String; const ValueInt: Int64);
> Var V, currentHeader: String;
> i: integer;
> function GetSizeFromHeader(Header: String): integer;
> Var item: TStringList;
> begin
> //the download size is contained in the header (e.g.: Content-Length:
> 3737722)
> Result := -1;
>
> if Pos('Content-Length:', Header) <> 0 then begin
> item := TStringList.Create();
> item.Delimiter := ':';
> item.StrictDelimiter :=true;
> item.DelimitedText :=Header;
> if item.Count = 2 then begin
> Result:= StrToInt(Trim(item[1]));
> end;
> end;
> end;
> begin
> //try to get filesize from headers
> if Assigned(xOnReceiveData) then
> if (DownloadSize < 1) then begin
> for i := 0 to hSock.Headers.Count - 1 do begin
> currentHeader := hSock.Headers[i];
> DownloadSize := GetSizeFromHeader(currentHeader);
> if DownloadSize <> -1 then break;
> end;
> end;
>
> //HR_ReadCount contains the number of bytes since the last event
> if Reason = THookSocketReason.HR_WriteCount then begin
> if Assigned(xOnSendData) then xOnSendData(ValueInt);
> end;
> if DownloadSize > 0 then
> if Reason = THookSocketReason.HR_ReadCount then begin
> if Assigned(xOnReceiveData) then xOnReceiveData(ValueInt,
> DownloadSize);
> end;
> end;
>
> So with this you will get a trigger as received data piles up, ValueInt =
> amount of data received on this trigger, let's say 8 KB, then you capture
> the event and sum up until you reach something like 50 MB, then write to a
> file and clear the HTTPSend.Document stream, repeat until download is
> finished.
>
> On 23 January 2017 at 17:45, Rainer Backes <rbac...@bond.de> wrote:
>
>> Hi,
>>
>> I would need a function/method to download a file via http/https directly
>> to disk, without using the memory stream inside the THTTPSend class - the
>> files that I have to download can be quite large (some GBs). Does anyone
>> already have such a function ?
>>
>> Thanks
>>
>> Rainer
>>
>> ------------------------------------------------------------
>> ------------------
>> Check out the vibrant tech community on one of the world's most
>> engaging tech sites, SlashDot.org! http://sdm.link/slashdot
>> _______________________________________________
>> synalist-public mailing list
>> synalist-public@lists.sourceforge.net
>> https://lists.sourceforge.net/lists/listinfo/synalist-public
>>
>>
>
------------------------------------------------------------------------------
Check out the vibrant tech community on one of the world's most
engaging tech sites, Slashdot.org! http://sdm.link/slashdot
_______________________________________________
synalist-public mailing list
synalist-public@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/synalist-public