                                   :key       key
                                   :exception err}))
            (close! res-ch)))
-    (.write ws (js/Uint8Array. (fress/write meta)))
+    (-serialize serializer buf write-handlers (update meta :key first))
+    (.write ws (js/Uint8Array. (js->clj (.from js/Array @buf))))
     (.end ws)
     res-ch))
 
-(defn write-edn [folder key up-fn]
+
+(defn write-edn [serializer write-handlers read-handlers folder key up-fn]
   (let [key       (uuid (first key))
         temp-file (str folder "/data/" key ".new")
         new-file  (str folder "/data/" key)

                                                         :key       key
                                                         :exception err}))
                                  (close! res-ch)))
                           (.write ws (js/Uint8Array. (fress/write value)))
                           (.close ws)))
        (.on rs "error" (fn [err]
                          (put! res-ch (ex-info "Could not write edn."

(ns konserve.filestore
  (:require
   [cljs.nodejs :as node]
   [konserve.core :as k]
   [hasch.core :refer [uuid]]
   [incognito.edn :refer [read-string-safe]]
   [konserve.serializers :as ser]
   [fress.api :as fress]
   [konserve.protocols :refer [PEDNAsyncKeyValueStore -exists? -get-in -update-in -assoc-in -dissoc
                               PJSONAsyncKeyValueStore -jget-in -jassoc-in -jupdate-in
                               PBinaryAsyncKeyValueStore -bget -bassoc
                               -serialize -deserialize]]
   [incognito.transit :refer [incognito-read-handler
                              incognito-write-handler]]
   [cognitect.transit :as transit]
   [cljs.core.async :as async :refer (take! <! >! put! take! close! chan poll!)]
   [cljs.tools.reader.impl.inspect :as i])
  (:require-macros [cljs.core.async.macros :refer [go go-loop]]))

;; TODO serializer
