Change. optional argument for easy:perform in Lua-cURL interface.

master
Alexey Melnichuk 2014-09-04 13:07:54 +05:00
parent 933c84db7d
commit f0c8ca020f
2 changed files with 21 additions and 18 deletions

View File

@ -1,47 +1,49 @@
local cURL = require("lcurl.cURL") local cURL = require("lcurl.cURL")
-- returns size and reader
local function make_stream(ch, n, m)
local size = n * m
local i = -1
return size, function()
i = i + 1
if i < m then
return (tostring(ch)):rep(n - 2) .. '\r\n'
end
end
end
c = cURL.easy_init() c = cURL.easy_init()
c:setopt_url("http://posttestserver.com/post.php") c:setopt_url("http://posttestserver.com/post.php")
c:setopt_post(true) c:setopt_post(true)
local length, reader = make_stream("a", 10, 4)
c:post{-- post file from private read function c:post{-- post file from private read function
-- Lua-cURL compatiable -- Lua-cURL compatiable
-- allows only one stream -- allows only one stream
name = { name = {
file="stream.txt", file="stream.txt",
stream_length="5", stream_length=length,
type="text/plain", type="text/plain",
} }
} }
count = 0 c:perform{readfunction = reader}
c:perform{readfunction = function(n)
if count < 5 then
count = 5
return "stream"
end
return nil
end}
local length, reader = make_stream("b", 10, 4)
c:post{-- post file from private read function c:post{-- post file from private read function
-- define stream callback -- define stream callback
name = { name = {
file = "stream.txt", file = "stream.txt",
type = "text/plain", type = "text/plain",
stream_length = 5, stream_length = length,
stream = function() stream = reader,
if count < 5 then
count = 5
return "STREAM"
end
return nil
end,
} }
} }
count = 0
c:perform{} c:perform{}
print("Done") print("Done")

View File

@ -83,6 +83,7 @@ function Easy:setopt_readfunction(fn, ...)
end end
function Easy:perform(opt) function Easy:perform(opt)
opt = opt or {}
local oerror = opt.errorfunction or function(err) return nil, err end local oerror = opt.errorfunction or function(err) return nil, err end