NodeMCU-HTTP-Server
NodeMCU-HTTP-Server copied to clipboard
Issue in `Res:sendFile()`
I've an issue in function Res:sendFile()
in the local function doSend()
: When the file length is a multiple of 512 (1024, 1536, 2048, ...) the function fails at the end of the file, since buf
is nil in self._skt:send(buf)
. Here's how I fixed it:
print('* Sending ', filename)
local pos, fin = 0, nil
local function doSend()
file.open(filename, 'r')
if file.seek('set', pos) == nil then
fin = 1
else
local buf = file.read(512)
pos = pos + 512
if buf == nil then
fin = 1
else
self._skt:send(buf)
end
end
file.close()
if fin then
self:close()
print('* Finished ', filename)
end
end
Great project, thanks for sharing!