 (ns datoteka.impl
   "Implementation details and helpers."
   (:require [datoteka.proto :as pt]
-            [datoteka.fs :as fs]
-            [buddy.core.codecs :as codecs]
+            [datoteka.core :as fs]
             [clojure.java.io :as io])
   (:import java.io.File
            java.io.ByteArrayInputStream

(extend-protocol pt/IContent
  String
  (-input-stream [v]
    (ByteArrayInputStream. (codecs/str->bytes v)))

  Path
  (-input-stream [v]
    (io/input-stream v))

  File
  (-input-stream [v]
    (io/input-stream v))

  URI
  (-input-stream [v]
    (io/input-stream v))

  URL
  (-input-stream [v]
    (io/input-stream v))

  InputStream
  (-input-stream [v]
    v)

  ratpack.http.TypedData
  (-input-stream [this]
    (.getInputStream this)))

(extend-protocol pt/IUri
  URI

  (make-output-stream [path opts]
    (let [^OutputStream os (path->output-stream path)]
      (io/make-output-stream os opts))))
