Make monger.gridfs.IOFactory implementation for String to work the same way as clojure.java.io/IOFactory one does
It treats string arguments as local filesystem paths
This commit is contained in:
parent
bb806d5c0f
commit
ced9b50153
2 changed files with 6 additions and 5 deletions
|
|
@ -4,7 +4,8 @@
|
||||||
[clojure.java.io :as io])
|
[clojure.java.io :as io])
|
||||||
(:use [monger.conversion])
|
(:use [monger.conversion])
|
||||||
(:import [com.mongodb DBObject]
|
(:import [com.mongodb DBObject]
|
||||||
[com.mongodb.gridfs GridFS GridFSInputFile]))
|
[com.mongodb.gridfs GridFS GridFSInputFile]
|
||||||
|
[java.io InputStream]))
|
||||||
|
|
||||||
;;
|
;;
|
||||||
;; Implementation
|
;; Implementation
|
||||||
|
|
@ -55,7 +56,7 @@
|
||||||
(extend-protocol GridFSInputFileFactory
|
(extend-protocol GridFSInputFileFactory
|
||||||
String
|
String
|
||||||
(make-input-file [^String input]
|
(make-input-file [^String input]
|
||||||
(.createFile ^GridFS monger.core/*mongodb-gridfs* (.getBytes input))))
|
(.createFile ^GridFS monger.core/*mongodb-gridfs* ^InputStream (io/make-input-stream input { :encoding "UTF-8" }))))
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -24,8 +24,8 @@
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
(deftest test-storing-strings-to-gridfs
|
(deftest test-storing-files-to-gridfs-using-relative-fs-paths
|
||||||
(let [input "A string"]
|
(let [input "./test/resources/mongo/js/mapfun1.js"]
|
||||||
(is (= 0 (count (gridfs/all-files))))
|
(is (= 0 (count (gridfs/all-files))))
|
||||||
(gridfs/store (gridfs/make-input-file input)
|
(gridfs/store (gridfs/make-input-file input)
|
||||||
(.setFilename "monger.test.gridfs.file1")
|
(.setFilename "monger.test.gridfs.file1")
|
||||||
|
|
@ -37,6 +37,6 @@
|
||||||
(let [input (.getBytes "A string")]
|
(let [input (.getBytes "A string")]
|
||||||
(is (= 0 (count (gridfs/all-files))))
|
(is (= 0 (count (gridfs/all-files))))
|
||||||
(store (make-input-file input)
|
(store (make-input-file input)
|
||||||
(.setFilename "monger.test.gridfs.file1")
|
(.setFilename "monger.test.gridfs.file2")
|
||||||
(.setContentType "application/octet-stream"))
|
(.setContentType "application/octet-stream"))
|
||||||
(is (= 1 (count (gridfs/all-files))))))
|
(is (= 1 (count (gridfs/all-files))))))
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue