function httpGet(url) http.request(url) while true do local event, url, hBody = os.pullEvent() if event == "http_success" then return hBody elseif event == "http_failure" then error("Failed to HTTP GET " .. url) return nil end end end function processHttpBody(hBody, saveTo) if hBody then local body = hBody.readAll() local out = io.open(saveTo, "w") out:write(body) out:close() hBody.close() return 0 else hBody.close() return 1 end end function download(url, file) get = httpGet(url) if get then return processHttpBody(get, file) else return -1 end end