Start use datoteka.io ns

This commit is contained in:
Andrey Antukh 2022-08-31 13:29:43 +02:00 committed by Alonso Torres
parent 1e2d100c81
commit e657c1bbfa
10 changed files with 61 additions and 182 deletions

View file

@ -10,11 +10,10 @@
[app.common.spec :as us]
[app.common.uri :as u]
[app.storage.impl :as impl]
[app.util.bytes :as bs]
[clojure.java.io :as io]
[clojure.spec.alpha :as s]
[cuerdas.core :as str]
[datoteka.fs :as fs]
[datoteka.io :as io]
[integrant.core :as ig]
[promesa.core :as p]
[promesa.exec :as px])
@ -59,7 +58,7 @@
(fs/create-dir (fs/parent full)))
(with-open [^InputStream src (io/input-stream content)
^OutputStream dst (io/output-stream full)]
(io/copy src dst)))))
(io/copy! src dst)))))
(defmethod impl/get-object-data :fs
[{:keys [executor] :as backend} {:keys [id] :as object}]
@ -76,8 +75,8 @@
(defmethod impl/get-object-bytes :fs
[backend object]
(p/let [input (impl/get-object-data backend object)]
(ex/with-always (bs/close! input)
(bs/read-as-bytes input))))
(ex/with-always (io/close! input)
(io/read-as-bytes input))))
(defmethod impl/get-object-url :fs
[{:keys [uri executor] :as backend} {:keys [id] :as object} _]

View file

@ -9,10 +9,10 @@
(:require
[app.common.data.macros :as dm]
[app.common.exceptions :as ex]
[app.util.bytes :as bs]
[buddy.core.codecs :as bc]
[buddy.core.hash :as bh]
[clojure.java.io :as io])
[clojure.java.io :as jio]
[datoteka.io :as io])
(:import
java.nio.ByteBuffer
java.nio.file.Files
@ -110,14 +110,14 @@
IContentObject
(get-size [_] size)
io/IOFactory
jio/IOFactory
(make-reader [this opts]
(io/make-reader this opts))
(jio/make-reader this opts))
(make-writer [_ _]
(throw (UnsupportedOperationException. "not implemented")))
(make-input-stream [_ _]
(-> (io/input-stream path)
(bs/bounded-input-stream size)))
(io/bounded-input-stream size)))
(make-output-stream [_ _]
(throw (UnsupportedOperationException. "not implemented")))))
@ -127,14 +127,14 @@
IContentObject
(get-size [_] size)
io/IOFactory
jio/IOFactory
(make-reader [this opts]
(io/make-reader this opts))
(jio/make-reader this opts))
(make-writer [_ _]
(throw (UnsupportedOperationException. "not implemented")))
(make-input-stream [_ _]
(-> (bs/bytes-input-stream data)
(bs/bounded-input-stream size)))
(-> (io/bytes-input-stream data)
(io/bounded-input-stream size)))
(make-output-stream [_ _]
(throw (UnsupportedOperationException. "not implemented")))))
@ -169,7 +169,7 @@
(when-not (satisfies? IContentObject content)
(throw (UnsupportedOperationException. "`content` should be an instance of IContentObject")))
(when-not (satisfies? io/IOFactory content)
(when-not (satisfies? jio/IOFactory content)
(throw (UnsupportedOperationException. "`content` should be an instance of IOFactory")))
(reify
@ -179,15 +179,15 @@
IContentHash
(get-hash [_] hash)
io/IOFactory
jio/IOFactory
(make-reader [_ opts]
(io/make-reader content opts))
(jio/make-reader content opts))
(make-writer [_ opts]
(io/make-writer content opts))
(jio/make-writer content opts))
(make-input-stream [_ opts]
(io/make-input-stream content opts))
(jio/make-input-stream content opts))
(make-output-stream [_ opts]
(io/make-output-stream content opts))))
(jio/make-output-stream content opts))))
(defn content?
[v]