easy:SetOpt_WriteFunction(write_callback[, userdata])
The first parameter that is passed to your callback function is a string that
contains the raw binary data just received. If you pass the optional userdata
argument, the value you pass in userdata
will be passed to your callback function as
a second parameter. The userdata
parameter can be of any type.
The callback function will be passed as much data as possible in all invokes,
but you must not make any assumptions. It may be one byte, it may be
thousands. The maximum amount of body data that will be passed to the write
callback is defined as follows: #CURL_MAX_WRITE_SIZE
(the
usual default is 16K). If #CURLOPT_HEADER
is enabled, which makes
header data get passed to the write callback, you can get up to
#CURL_MAX_HTTP_HEADER
bytes of header data passed into it. This usually
means 100K.
This function may be called with zero bytes data if the transferred file is empty.
Your callback should return the number of bytes actually taken care of. If
that amount differs from the amount passed to your callback function, it'll
signal an error condition to the library. This will cause the transfer to get
aborted and the libcurl function used will return #CURLE_WRITE_ERROR
.
If your write function returns nothing, this will signal success and the transfer will be continued.
If your callback function returns #CURL_WRITEFUNC_PAUSE
it will cause this
transfer to become paused. See easy:Pause() for further details.
Function p_WriteData(data$) WriteBytes(1, data$) EndFunction e:SetOpt_WriteFunction(p_WriteData)The code above will install a write function that will write all data it receives to the file using the identifier 1.