i am currently trying to download files from github (and yes i know about wget) and i need to know if they exist or not (making a list of all existing files is not feasible, because there is not enough space on the disk for the list).
I tried multiple things:
1. wget and filesystem.size always gave a length of 0 even for existing files
2. copying wget in my own program and setting a flag if there is a chunk works ... but not with every file (all files that exist have the same structure and length) and i need all of the existing ones them
Now i tried to do it myself with internet.request() but i only get 4 files (also the empty ones) then 6 fail and 4 succeed again(see test.txt t = True and f = False). This is because of to many open connections and i do not know how to close them.
The internet.close() from the wiki dose not work for some reason. (attempt to call nil)
How can i detect if the file exists and close the connection after the download?
local c = require("component")
local internet = require("internet")
local f = io.open("test.txt", "wb")
imax = 0
xmax = 75
ymax = 180
zmax = 87
line = ""
link = "https://raw.githubusercontent.com/LordNocturnus/sf-"
folder = "/master/"
pos = 0
i = 0
while i <= imax do
xb = pos
while xb <= xmax do
yb = 0
while yb <= ymax do
zb = 0
while zb <= zmax do
print(xb,yb,zb)
file = tostring(xb) .. "-" .. tostring(yb) .. "-" .. tostring(zb) .. ".mb3d"
status, user = pcall(internet.request ,link .. tostring(i) .. folder .. file)
print(status)
print(user)
-- for i,v in pairs(user) do
-- print(i,v)
-- end
if status then
line = line .. "t"
else
line = line .. "f"
end
-- internet.close()
-- f = io.open(file, "wb")
-- for chunk in user do
-- print(chunk)
-- f:write(chunk)
-- end
-- f:close()
-- fs.remove("home/" .. file)
zb = zb+1
end
yb = yb+1
end
xb = xb+1
end
i = i+1
end
f:write(line)
f:close()
You can post now and register later.
If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.
Hello
i am currently trying to download files from github (and yes i know about wget) and i need to know if they exist or not (making a list of all existing files is not feasible, because there is not enough space on the disk for the list).
I tried multiple things:
1. wget and filesystem.size always gave a length of 0 even for existing files
2. copying wget in my own program and setting a flag if there is a chunk works ... but not with every file (all files that exist have the same structure and length) and i need all of the existing ones them
Now i tried to do it myself with internet.request() but i only get 4 files (also the empty ones) then 6 fail and 4 succeed again(see test.txt t = True and f = False). This is because of to many open connections and i do not know how to close them.
The internet.close() from the wiki dose not work for some reason. (attempt to call nil)
How can i detect if the file exists and close the connection after the download?
test.txt:
tttttffffffffttttffffffttttffffffttttffffffttttffffffttttffffffttttffffffttttfffffft
internet.lua:
local c = require("component")
local internet = require("internet")
local f = io.open("test.txt", "wb")
imax = 0
xmax = 75
ymax = 180
zmax = 87
line = ""
link = "https://raw.githubusercontent.com/LordNocturnus/sf-"
folder = "/master/"
pos = 0
i = 0
while i <= imax do
xb = pos
while xb <= xmax do
yb = 0
while yb <= ymax do
zb = 0
while zb <= zmax do
print(xb,yb,zb)
file = tostring(xb) .. "-" .. tostring(yb) .. "-" .. tostring(zb) .. ".mb3d"
status, user = pcall(internet.request ,link .. tostring(i) .. folder .. file)
print(status)
print(user)
-- for i,v in pairs(user) do
-- print(i,v)
-- end
if status then
line = line .. "t"
else
line = line .. "f"
end
-- internet.close()
-- f = io.open(file, "wb")
-- for chunk in user do
-- print(chunk)
-- f:write(chunk)
-- end
-- f:close()
-- fs.remove("home/" .. file)
zb = zb+1
end
yb = yb+1
end
xb = xb+1
end
i = i+1
end
f:write(line)
f:close()
Link to post
Share on other sites