I have a Vapor server running and it's creating files. Those files are temporary files, so they should not stay on the server.
Currently I use the following:
let data = try Data(contentsOf: tempURL)
try FileManager.default.removeItem(at: tempURL)
let response = Response(status: .ok, headers: HTTPHeaders(headers), body: Response.Body(data: data))
So I read the contents of the file, delete that file (as it's temporary only) and then respond with it.
The problem that I now see is that sometimes, very hard to reproduce, the contents of that file is only submitted partially. I don't know exactly what the problem is yet, but I did some digging and at least found a Radar (https://openradar.appspot.com/39621032), saying that this function isn't working like it should on Linux (which I use.. I use it in a Docker-Container)
So just to make sure this is not the problem, I'd like to know the Vapor way of responding with a file and then deleting it afterwards?!?