Fix - make fileHandle and clean it up, so it plays nice with coroutines.
This commit is contained in:
parent
45edb29368
commit
dba1ca7968
@ -9,16 +9,19 @@ return function (connection, req, args)
|
||||
-- Chunks larger than 1024 don't work.
|
||||
-- https://github.com/nodemcu/nodemcu-firmware/issues/1075
|
||||
local chunkSize = 1024
|
||||
fileHandle = file.open(args.file)
|
||||
local fileHandle = file.open(args.file)
|
||||
while bytesRemaining > 0 do
|
||||
local bytesToRead = 0
|
||||
if bytesRemaining > chunkSize then bytesToRead = chunkSize else bytesToRead = bytesRemaining end
|
||||
local chunk = fileHandle:read(bytesToRead)
|
||||
connection:send(chunk)
|
||||
bytesRemaining = bytesRemaining - #chunk
|
||||
--print(args.file .. ": Sent "..#chunk.. " bytes, " .. bytesRemaining .. " to go.")
|
||||
chunk = nil
|
||||
collectgarbage()
|
||||
end
|
||||
print("Finished sending: ", args.file)
|
||||
fileHandle:close()
|
||||
fileHandle = nil
|
||||
collectgarbage()
|
||||
end
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user