CC: Tweaked

CC: Tweaked

57M Downloads

wget fails when downloading empty files

SquidDev opened this issue ยท 4 comments

commented

When downloading an empty file, wget prints "Success" but fails to actually save the file. This is because readAll() returns nil when reading empty files:

local contents = http.get("https://raw.githubusercontent.com/xiondisc/CC-Test/5c4648b5bba5630953e3d09f08bc199fd15bf69c/TurtleTest/turtleTest.lua", nil, true)
print(contents.readAll()) -- nil!
contents.close()

This is correct behaviour (judging by what PUC Lua does), so we should fix this on the wget side.

commented

Good to know

commented

While we're documenting wget bugs, looks like we also fail to do any error handling on fs.open calls:

https://github.com/SquidDev-CC/CC-Tweaked/blob/2fab1a3054c82f3c74d2e01a0fe6854f6c0df724/src/main/resources/data/computercraft/lua/rom/programs/http/wget.lua#L82

Should probably do something like:

local file, err = ...
if not file then
  printError(err)
  return
end
commented

What would you suggest to print out if the responce.readAll() is nil?

Remote file is empty.?
Got empty reponse.?

commented

It should print out Downloaded as xxx, and write the file :p.