Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
InputStream wrapper which calls given callback after the stream is closed.
(ns example
(:import java.io.FilterInputStream))
(defn cleanup-input-stream
"InputStream wrapper which calls given callback after
the stream is closed."
[is cleanup]
(proxy [FilterInputStream] [is]
(close []
(proxy-super close)
(cleanup))))
(defn input-stream-in-tmp-dir [...]
(let [dir (create-tmp-dir)
file (generate-file dir)
cleanup #(delete-tmp-dir dir)]
(cleanup-input-stream (input-stream file) cleanup))
(with-open [is (input-stream-in-tmp-dir ...)]
(io/copy is ....))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment