                                      :locks          (atom {})
                                      :config         config}))))
 
+
 (comment
-  ;create store
+                                        ;create store
   (go (def store (<! (new-fs-store "/tmp/mystore"))))
 
-  (delete-store "mystore")
-  ;exists?
-  
+  (delete-store "/tmp/mystore")
+
+  ;;EDN read/write functionality
   (go (println (<! (-assoc-in store [:new] 43))))
-  (go (println (<! (-exists? store :new)))) 
+
+  (go (println (<! (-exists? store :new))))
   (go (println (<! (-update-in store [:new] inc))))
-  (go (println (<! (-get-in store [:new]))))
+  (go (def x (<! (-get-in store [:new]))))
   (go (println (<! (-dissoc store :new))))
-
-
-;;Input, Outputstream
-
-(def my-obj (clj->js {:key "123" :format :edn}))
-
-(defn- read-key
-  [filename key]
-  (when (.existsSync fs path)
-    (let [rs (.createReadStream fs path)]
-      (.on rs "data" (fn [chunk] (set! scope (.toString chunk))))
-      (.on rs "close" #(println "Reading done"))
-      (.on rs "error" (fn [err] (println "error: " err))))))
-
-
-
-
-
-
-
-
-
-
-(write-edn-key "/tmp" {:key "123" :format :edn})
-
-
-
-
-
-
-(def rc (chan))
-
-(go (println (<! (read-edn "/tmp" "123"))))
-
-(defn read-my-key []
-  (let [value (js-obj)]
-    (go (set! (.-var value) (<! (read-edn "/tmp" "123"))))
-    value))
-
-(read-my-key)
-
-(write-edn "myfile.txt" "Hello World")
-
-(take! (read-edn "/tmp" "123") #(println %))
-
-(def myatom (atom {}))
-
-(poll! (read-edn "/tmp" "123"))
-
-(async/reduce (<! (read-edn "/tmp" "123")))
-
-;read back use -> cljs.reader/read-string
-(cljs.reader/read-string (prn-str {:x "123" :y "123"}))
-
+  (doseq [i (range 1 10)]
+    (go (<! (-assoc-in store [i] (+ i i)))))
+  ;;Binary read/write functionality
+  (go (println (<! (-bassoc store [:bin1ary] (js/Buffer.from #js [1 2 3 4])))))
+
+  ;,invalid input for write binary
+
+  (go (println (<! (-bassoc store [:binary] (.createReadStream fs "/tmp/mystore/data/2d081fba-8060-59dd-aa19-7b61d4a2d504")))))
+
+
+  (go (println (<! (-bassoc store [:binary] "123"))))
+
+
+  (go (<! (-bget store [:binary] #(println %))))
+
+
+  (prn "123")
+
+  (ex-info "Write binary input is not a stream or buffer."
+           {:type      :write-binary-error
+            :key       key
+            :exception err})
+
+
+
+  (instance? #object[ReadStream] "123")
+
+  (type (.createReadStream fs "/tmp/mystore/data/2d081fba-8060-59dd-aa19-7b61d4a2d504"))
+
+  (type (.createReadStream fs "/tmp/mystore/data/2d081fba-8060-59dd-aa19-7b61d4a2d504"))
+
+  (def inMemory (atom nil))
+
+  (go (.pipe (<! (-bget store :binary #())) (.createWriteStream fs "temp1234")))
+
+
+  ;; TODO no vector for key
+  (go (<! (-bget store [:binary] #(.pipe (:read-stream %)
+                                         (.createWriteStream fs "temp1234")))))
+
+  (go (<! (-bget store [:binary] #(-bassoc store [:other-binary] (:read-stream %)))))
+
+  ;;Copy binary
+
+(def mybuf (js/Buffer.from #js [1 2 3 4]))
+
+(def ymstream (stream.PassThrough))
+
+(.end ymstream mybuf)
+
+(type ymstream)
+
+(time (spit "xwerqwer" "qwerqwerqwer"))
+
+(time )
+
+(time (write-binary "/tmp/mystore" "12341234" "1234123412341234"))
+
+
+(slurp "myfile")
+
+
+
+
+
+
+
+
+
+(go
+  (let [[err] (<! (io/aspit "data.edn" data))]
+            (if-not err
+              (println "you've successfully written to 'data.edn'")
+              (println "there was an error writing: " err))))
+
+(go
+  (let [[err datastring] (<! (io/aslurp "data.edn"))]
+    (if-not err
+      (handle-data (read-string datastring))
+      (handle-error err))))
+
+
+
+
+(type ymstream)
+
+(if (js/Buffer.isBuffer mybuf)
+  (println "i a m buffer")
+  false)
+
+(def new-array (apply vector (range 1 10)))
+
+new-array
+
+(def myarray )
+
+myarray
+
+
+(go (println (<! (-bassoc store :testy ))))
+
+(uuid :testy)
+
+(go (.pipe (<! (-bget store :testy)) (.createWriteStream fs "/tmp/1234")))
+
+
+(list-keys store)
+
+(go (<! (write-binary-new "/tmp/mystore" "123" mybuf)))
+
+
+(write-binary-new "/tmp/mystore" "123" mybuf)
+
+
+
+
+(def mychan (chan))
+
+(put! mychan (ex-info "Could not write binary."
+                      {:type      :write-binary-error
+                       :key       "123"
+                       :exception "123"}))
+
+(take! mychan #(prn %))
+
+
+)
+
+

  (:require [cljs.nodejs :as node]
            [konserve.core :as k]
            [hasch.core :refer [uuid]]
            [konserve.serializers :as ser]
            [konserve.protocols :refer [PEDNAsyncKeyValueStore -exists? -get-in -update-in -assoc-in -dissoc
                                        PJSONAsyncKeyValueStore -jget-in -jassoc-in -jupdate-in
                                        PBinaryAsyncKeyValueStore -bget -bassoc
                                        -serialize -deserialize]]
            [cljs.core.async :as async :refer (take! <! >! put! close! chan poll!)])
  (:require-macros [cljs.core.async.macros :refer [go go-loop]]))


  (-get-in [this key-vec]
    (read-edn folder (first key-vec)))
  (-update-in [this key-vec up-fn]
    (go (<! (write-edn-key folder {:key key-vec :format :edn}))
        (<! (write-edn folder key-vec up-fn))))
  (-assoc-in [this key-vec val] (-update-in this key-vec (fn [_] val)))
  (-dissoc [this key] (let [fn (uuid key)
                            res-ch (chan)]
                        (delete-entry folder fn res-ch)
                        res-ch))
  PBinaryAsyncKeyValueStore
  (-bget [this key locked-cb] (read-binary folder key locked-cb))
  (-bassoc [this key input] (do (write-edn-key folder {:key key :format :binary})
                                (println "start write binary")
                                (write-binary folder (first key) input))))

(defn new-fs-store
  "Filestore contains a Key and a Data Folder"
