   [input]
   ; TODO: ensure `mark` is supported
   (if (read-header! input)
-    (let [primary-bytes (ByteArrayOutputStream.)
-          reader (-> input
-                     (capturing-input-stream primary-bytes)
-                     (InputStreamReader. blob-charset)
-                     LineNumberingPushbackReader.)
-          primary-value (edn/read reader)]
-      ; TODO: specify readers? {:readers puget.data/data-readers}
-      (when (thread-bound? #'*primary-bytes*)
-        (set! *primary-bytes* (.toByteArray primary-bytes)))
+    (let [reader (InputStreamReader. input blob-charset)
+          primary-value (read-primary-value! reader)]
       ; TODO: read remaining values from the stream
       primary-value)
     input))

        false))))


(defn- capturing-input-stream
  "Wraps the given input stream with a proxy which will record the bytes read
  to the given output stream."
  [input output]
  (proxy [FilterInputStream] [input]
    (read
      ([]
       (let [b (.read input)]
         (.write output b)
         b))
      ([buf off len]
       (let [n (.read input buf off len)]
         (.write output buf off n)
         n)))))


(def ^:dynamic *primary-bytes*
  "If bound when `read-data` is called, this var is set to an array containing
  the bytes which comprise the 'primary' EDN value in a data blob. These bytes
  are the target for inline signatures."
  nil)


(defn read-data

    [fipp.printer :refer [pprint-document]]
    [puget.printer :as puget])
  (:import
    java.io.ByteArrayOutputStream
    java.io.FilterReader
    java.io.InputStreamReader
    java.io.OutputStreamWriter
    java.io.PushbackReader
    java.nio.charset.Charset))


