I make my first web server on Lua, and now I need to send a picture, and only the word PNG comes to the browser and nothing else.

In C # there is a File.ReadAllBytes(path) method File.ReadAllBytes(path) it reads all the bytes from the file. Is there a similar in Lua? Rummaged all documentation, but did not find. I stopped at io.open(path,"rb"):read("*all") .

  • well everything is correct, open("rb") - Mike V.

1 answer 1

You do everything right. Slightly more complete and correct version:

 local file = assert(io.open(path, 'rb')) -- Открыть файл с проверкой assert local data = file:read '*a' -- Прочитать все данные file:close() -- Закрыть файл 

After that, data will contain the contents of the file byte-by-byte.

  • one
    not file: read? - eri
  • @eri thanks, wrong. - val
  • io.read(), we read a line from the standard and where do we read about? - eri
  • @eri What kind of day is this, I screwed up everywhere: D - val