Download with Sockets

1

I'm using LuaSocket and wanted to download files with it, but I do not know like, I was able to download text file like this:

local file = io.open("Blabla.txt", "w")
file:write(tostring(http.request("Http://pokestage.ddns.net/patch/News.txt")))
file:close()
io.write("Downloaded!\n")
io.read()

How could I download files from other formats? (Exe, rar ...)

@Edit: I tried:

arq = http.request("http://pokestage.ddns.net/patch/1.7z")
for ind, val in pairs(arq) do
print(ind)
end

Returned: Table expected, got string. . But when I try to write, it still does not work.

    
asked by anonymous 31.10.2014 / 23:47

1 answer

3

I was not getting it because I was opening a binary file in text mode. When I changed "w" (write) to "wb" (write binary), I did it. It looks like this:

local file = io.open("1.7z", "wb")
file:write(tostring(http.request("Http://pokestage.ddns.net/patch/1.7z")))
file:close()
io.write("Downloaded!\n")
io.read()

Exactly what Maniero said.

    
30.12.2014 / 12:13