local config = require("config") local function archive(req) local archive = assert(io.open(config.approot .. "data/archive.zip","rb")) --[=[ local archive_size = archive:seek("end") archive:seek("set") local archive_cursor = 0 local co = coroutine.create(function() print("Inside coroutine!") --[[ for i = 1,10 do local str = {tostring(i),":",} for i = 1,10 do table.insert(str,tostring(math.random())) end coroutine.yield(table.concat(str)) end ]] for i = 1, 1000 do coroutine.yield("Hello, world!" .. tostring(i)) end --[[ while archive_cursor ~= archive_size do print("Inside while") local bytes_left = archive_size - archive_cursor local next_chunk = math.min(4096,bytes_left) print("Before yield") coroutine.yield(archive:read(next_chunk)) print("After yield") end archive:close() ]] end) print("co status:",coroutine.status(co)) --local bytes_start,bytes_end = 0, 200 --http_response_header(req,"content-type","application/zip") --http_response_header(req,"accept-ranges","bytes") http_response_header(req,"transfer-encoding","chunked") http_response_co(req,co) print("a print after our response") --[[ local bytes_start,bytes_end = 0, 200 http_response_header(req,"content-type","application/zip") http_response_header(req,"accept-ranges","bytes") assert(archive:seek("set",bytes_start)) local data = assert(archive:read(bytes_end - bytes_start)) http_response_stream(req,200,data,function() print("Callback completed!") end) ]] ]=] http_response_header(req,"Content-Disposition","attachment; filename=\"slash_monster_archive.zip\"") http_response(req,200,archive:read("*a")) archive:close() end return archive