easy:SetOpt_ReadFunction(read_callback[, userdata])
The first parameter that is passed to your callback function is an integer that
contains the number of bytes that should be read. 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.
Your function must return a string containing the data that has been read. This may contain less bytes than requested but there must be at least one byte in the return string or the transfer will be aborted.
If you stop the current transfer by returning an empty string (i.e before the server expected it, like when you've said you will upload N bytes and you upload less than N bytes), you may experience that the server "hangs" waiting for the rest of the data that won't come.
The read callback may return #CURL_READFUNC_ABORT
to stop the current
operation immediately, resulting in a #CURLE_ABORTED_BY_CALLBACK
error
code from the transfer.
The callback can return #CURL_READFUNC_PAUSE
to cause reading from this
connection to pause. See easy:Pause() for further details.
Bugs: when doing TFTP uploads, you must return the exact amount of data that the callback wants, or it will be considered the final packet by the server end and the transfer will end there.
Function p_ReadData(len) If readlen + len > totallen Then len = totallen - readlen If len > 0 readlen = readlen + len Return(ReadBytes(1, len)) Else Return("") EndIf EndFunction readlen = 0 totallen = FileLength(1) e:SetOpt_ReadFunction(p_ReadData)The code above installs a read function that will read all data from the file using the identifier 1.