You cannot select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
koreader/plugins/newsdownloader.koplugin/internaldownloadbackend.lua

25 lines
900 B
Lua

local http = require("socket.http")
local https = require("ssl.https")
local logger = require("logger")
local ltn12 = require("ltn12")
local socket_url = require("socket.url")
local InternalDownloadBackend = {}
function InternalDownloadBackend:getResponseAsString(url)
local resp_lines = {}
local parsed = socket_url.parse(url)
local httpRequest = parsed.scheme == 'http' and http.request or https.request
httpRequest({ url = url, sink = ltn12.sink.table(resp_lines), })
return table.concat(resp_lines)
end
function InternalDownloadBackend:download(link, path)
logger.dbg("InternalDownloadBackend: News file will be stored to :", path)
local parsed = socket_url.parse(link)
local httpRequest = parsed.scheme == 'http' and http.request or https.request
httpRequest({ url = link, sink = ltn12.sink.file(io.open(path, "w")), })
end
return InternalDownloadBackend