Last active
October 19, 2020 07:10
-
-
Save mpenet/b3e2c3a79f226c6963b036777f70c9ce to your computer and use it in GitHub Desktop.
copy.clj
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
(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