ring

jumar 2024-10-04T08:27:12.754429Z

I have a handler that returns file to be downloaded by the user. It's something like

(defn- download [req]
  (let [data ...
        temp-file (File/createTempFile bucket data-file-path)]
    (spit temp-file data)
    temp-file))
I would like to delete this file as soon as possible without having to resort to some kind of periodical background cleanup process. Is that possible?

weavejester 2024-10-04T17:53:44.431379Z

If you're running under Linux or some other Unix-like system (like MacOS), then you can open the file as a stream, then immediately delete the original file. Linux will keep files around until all file handles have been closed, so as long as the InputStream exists and is open, the data will remain on disk.

jumar 2024-10-04T17:54:28.712959Z

Yes, I am. Thanks for the tip. I will try that