diff --git a/CHANGELOG.md b/CHANGELOG.md index f6b45cb..3a58543 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -4,8 +4,9 @@ For a list of breaking changes, check [here](#breaking-changes). Babashka [fs](https://github.com/babashka/fs): file system utility library for Clojure -## Unreleased +## v0.4.18 (2023-05-11) +- [#48](https://github.com/babashka/fs/issues/48): support input-stream in `fs/copy` - [#91](https://github.com/babashka/fs/issues/91): add 1-arity to `xdg-*-home` to get subfolder of base directory ([@eval](https://github.com/eval)) - [#94](https://github.com/babashka/fs/issues/94): updates to `which`: add `:paths` `opt`, allow absolute paths for `program` ([@lread](https://github.com/lread)) diff --git a/src/babashka/fs.cljc b/src/babashka/fs.cljc index ab61888..2b957bc 100644 --- a/src/babashka/fs.cljc +++ b/src/babashka/fs.cljc @@ -354,16 +354,18 @@ * `:copy-attributes` * `:nofollow-links` (used to determine to copy symbolic link itself or not)." ([src dest] (copy src dest nil)) - ([src dest {:keys [:replace-existing - :copy-attributes - :nofollow-links]}] + ([src dest {:keys [replace-existing + copy-attributes + nofollow-links]}] (let [copy-options (->copy-opts replace-existing copy-attributes false nofollow-links) - dest (as-path dest)] - (if (directory-simple? dest) - (Files/copy (as-path src) (path dest (file-name src)) - copy-options) - (Files/copy (as-path src) dest - copy-options))))) + dest (as-path dest) + dest (if (directory-simple? dest) + (path dest (file-name src)) + dest) + input-stream? (instance? java.io.InputStream src)] + (if input-stream? + (Files/copy ^java.io.InputStream src dest copy-options) + (Files/copy (as-path src) dest copy-options))))) (defn posix->str "Converts a set of PosixFilePermission to a string." diff --git a/test/babashka/fs_test.clj b/test/babashka/fs_test.clj index e52f111..b35b9cc 100644 --- a/test/babashka/fs_test.clj +++ b/test/babashka/fs_test.clj @@ -175,7 +175,12 @@ (is (not (fs/exists? dest-file))) (testing "copying into dir" (fs/copy src-file dest-dir) - (is (fs/exists? dest-file))))) + (is (fs/exists? dest-file))) + (testing "copying input-stream" + (fs/delete dest-file) + (fs/copy (io/input-stream (fs/file src-file)) dest-file) + (is (fs/exists? dest-file)) + (is (= (slurp (fs/file src-file)) (slurp (fs/file dest-file))))))) (deftest copy-tree-test (let [tmp-dir (temp-dir)]