4D cURL
Description
curl (Client URL) is a command-line tool for transferring data to and from servers using a wide range of protocols — HTTP, HTTPS, FTP, SFTP, and more. This component provides a class-based generic API with callback functions to use curl from 4D.
README
cURL
aknowledgements: stunnel/static-curl
stunnel/static-curl is a static redistributable build of the popular curl CLI program. This component provides a wrapper class for calling it via SystemWorker.
Usage
To get version information:
var $version : Object
$version:=cs.curl.curl.new().version()To perform basic download with no progress callback:
#DECLARE($params : Object)
If ($params=Null)
CALL WORKER(1; Current method name; {})
Else
$URL:="https://resources-download.4d.com/release/20.x/20.5/latest/mac/tool4d_arm64.tar.xz"
$out:=Folder(fk desktop folder).file("tool4d_arm64.tar.xz")
$events:={}
$events.onResponse:=Formula(ALERT([$2.context.fullName; "downloaded!"].join(" ")))
$events.onData:=Formula(MESSAGE([$2.context.fullName; $2.percentage; "%"].join(" ")))
$events.onTerminate:=Formula(ALERT("terminated!"))
$events.onError:=Formula(ALERT("error!"))
$tasks:=[]
/*
any element that is an object not a file or folder is considered a context object
context object can have 2 properties: .data, .file
.data is a variant that is passed to the callback
.file is used as the stdin (assuming you pass @ - or -)
it can be 4D.File, 4D.Blob, Blob, or Text
*/
$tasks.push([$URL; "-o"; $out; "-L"; "-k"; {data: $out; file: Null}])
var $curl : cs.curl.curl
$curl:=cs.curl.curl.new()
$results:=$curl.execute($tasks; $events)
End if there are 2 ways to invoke .execute(); synchronous and asynchronous.
synchronous: pass a single parameter and receive a collection of results in return.
you can pass a single object or a collection of objects in a single call.
asynchronous: pass a second formula parameter. an empty collection is returned at this point.
the formula should have the following signature:
#DECLARE($worker : 4D.SystemWorker; $params : Object)
var $text : Text
$text:=$worker.response