1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71
|
{$mode objfpc}
{$h+}
unit pkgoCurl;
interface
uses Classes,pkgdownload;
Type
TOCurlDownloader = Class(TBaseDownloader)
Private
FCurl : String;
Protected
Procedure OCurlDownload(Const URL : String; Dest : TStream); virtual;
Procedure FTPDownload(Const URL : String; Dest : TStream); override;
Procedure HTTPDownload(Const URL : String; Dest : TStream); override;
Public
Property Curl : String Read FCurl Write FCurl;
end;
implementation
uses sysutils,curlobj,pkgmessages;
Procedure TOCurlDownloader.OCurlDownload(Const URL : String; Dest : TStream);
Var
ACurl : TCurl;
FN : String;
F : TFileStream;
begin
FN:=GetTempFileName();
Try
ACurl:=TCurl.Create(Nil);
Try
ACurl.URL:=URL;
ACurl.OutputFile:=FN;
ACurl.NoProgress:=True;
ACurl.Verbose:=False;
ACurl.FollowLocation:=True;
If Not ACurl.Perform then
Error(ACurl.ErrorString);
Finally
ACurl.Free;
end;
F:=TFileStream.Create(FN,fmOpenRead);
Try
Dest.CopyFrom(F,0);
Finally
F.Free;
end;
Finally
If FileExists(FN) then
DeleteFile(FN);
end;
end;
Procedure TOCurlDownloader.FTPDownload(Const URL : String; Dest : TStream);
begin
OCurlDownload(URL,Dest);
end;
Procedure TOCurlDownloader.HTTPDownload(Const URL : String; Dest : TStream);
begin
OCurlDownload(URL,Dest);
end;
end.
|