Skip to content

Instantly share code, notes, and snippets.

@mpenet
Last active October 19, 2020 07:10
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save mpenet/b3e2c3a79f226c6963b036777f70c9ce to your computer and use it in GitHub Desktop.
Save mpenet/b3e2c3a79f226c6963b036777f70c9ce to your computer and use it in GitHub Desktop.
copy.clj
(defn copy!
[src dest]
(with-open [src-input (FileInputStream. (io/file src))
dest-output (FileOutputStream. (io/file dest))
src-ch (.getChannel src-input)
dest-ch (.getChannel dest-output)]
(let [size (.size src-ch)]
(loop [position 0]
(when (< position size)
(recur (unchecked-add position
(.transferTo src-ch
position
size
dest-ch))))))))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment