This is a read-only snapshot of the ComputerCraft forums, taken in April 2020.
olie304's profile picture

Download PNG for CCLights2; Weird encoding?

Started by olie304, 12 September 2017 - 04:06 AM
olie304 #1
Posted 12 September 2017 - 06:06 AM
Hi, I am currently trying to download a picture off of my web server or the internet in general for usage on CCLights2 Monitors. The file downloads but for some reason it isn't a complete file (probably some kinda encoding issue somewhere). The file size is usually almost the same except off by a few bytes. When looking at the file in the programs folder windows just tells me it is a corrupted file.

I have been using something like this:


local file = fs.open("logo.png","w")
img = http.get("http://testsite.net/logo.png")
out = img.readAll()
img.close()
file.write(out)
file.close()
gpu = peripheral.wrap("right")

local lp = fs.combine(shell.getRunningProgram(),"..")
  fs.copy(fs.combine(lp,"logo.png"),"temp.png")
  local t = gpu.import("temp.png")
  fs.delete("temp.png")
  gpu.setColor(255,255,255)
  gpu.drawTexture(t,0,0)
  gpu.freeTexture(t)
 

But that didn't work. It gave an error (Don't know what it was because I re-created the PG and don't get any errors) so after some "intense" googling I found someone with a similar issue and tried their fix:


local response = http.get("https://www.google.com/images/srpr/logo3w.png")

if response then  local sResponse = response.readAll()
  response.close()
 
  local file = fs.open("file.png", "wb")
 
 
  for i = 1, #sResponse do
 
    file.write(string.byte(sResponse, i))
  end
 
  file.close()
 
end
local lp = fs.combine(shell.getRunningProgram(),"..")
fs.copy(fs.combine(lp,"file.png"),"temp.png")local t = gpu.import("temp.png")
fs.delete("temp.png")gpu.setColor(255,255,255)
gpu.drawTexture(t,0,0)
gpu.freeTexture(t)

All this does is runs with no errors and doesn't display anything.

Side note: Does anyone know where to find a good version of CCLights2? I tried the download on their main thread (github) and it only shows a blank white screen which sometimes has a colored box if you run the example program but not always. Their jenkins page is restricted now. There was a reply on the main thread which had the version I am using now that is pretty buggy but at least it is usable
Bomb Bloke #2
Posted 12 September 2017 - 06:54 AM
By default, ComputerCraft's web handles use text-mode. The first version to support binary-mode handles is 1.80, which is still in beta and certainly won't be compatible with any release of CCLights.

Prior to that, the usual workaround is to upload using base64 encoding and then decode back to the original file after downloading. BBPack can handle this for you.