lua-users home
lua-l archive

[Date Prev][Date Next][Thread Prev][Thread Next] [Date Index] [Thread Index]


On 2013/3/4 17:59, Michal Kottman wrote:
On 4 March 2013 10:42, Michal Kottman <michal.kottman@gmail.com> wrote:
local datafilename = "mydatafile"
local fhandle = assert(io.open(datafilename, "rb"))

c:perform({readfunction=function(n)
     -- read up to 4096 bytes from the file, and pass it back to libcurl
     -- if less than 4096 bytes are read (near the end of file),
libcurl will still process it
     -- at the end of file, it will return nil, which also signals
libcurl to stop
     return fhandle:read(4096)
end})
print("Fileupload done")
After better reading the docs, one warning - the `n` parameter you see
in readfunction is the maximal number of bytes libcurl expects. For my
setup it is 16KiB, so my example would work, but just to be safe (and
efficient) you should do this:

c:perform( { readfunction = function(n)
      return fhandle:read(n)
end } )


Michal Kottman, Thanks so much. You are very helpful.