-
-
Notifications
You must be signed in to change notification settings - Fork 646
http.download
Matthew Versluys edited this page Jun 6, 2016
·
15 revisions
Downloads an HTTP resource from the specified URL to a file.
http.download(url, file, { options })url is the URL to be downloaded.
file is the destination file that will be written to.
options is a table of options used for this HTTP retrieval
-
progressis a Lua callback function that receives two numeric arguments representing total and current download progress in bytes. -
headersis a Lua table with HTTP headers to be used on the request. -
userpwdis a username and optional password in the format of username:password which will be used to authenticate the request -
usernameis the username which will be used to authenticate the request -
passwordis the password which will be used to authenticate the request
There are two return values.
result_str, response_code = http.download(url, file, { options })-
result_stris set to "OK" if successful or contains a description of the failure. -
result_codeis the HTTP result code of the download.
local result_str, response_code = http.download("http://example.com/file.zip", "file.zip")function progress(total, current)
local ratio = current / total;
ratio = math.min(math.max(ratio, 0), 1);
local percent = math.floor(ratio * 100);
print("Download progress (" .. percent .. "%/100%)")
end
local result_str, response_code = http.download("http://example.com/file.zip", "file.zip", {
progress = progress,
headers = { "From: Premake", "Referer: Premake" },
userpwd = "username:password"
})The previous signature of this function was
http.download(url, file, progress, headers)and continues to be supported. This is equivalent to
http.download(url, file, { progress = progress, headers = headers })Premake 5.0 or later.