         (b58/decode source))))
 
 
-  InputStream
-
-  (decode
-    [source]
-    (let [code (.read source)
-          digest (read-stream-digest source)]
-      (create code digest))))
+  #?@(:clj
+      [InputStream
+
+       (decode
+         [source]
+         (let [code (.read source)
+               digest (read-stream-digest source)]
+           (create code digest)))]))

               (str "Encoded digest length " length " exceeds actual "
                    "remaining payload of " payload " bytes")
               {:type :multihash/bad-input})))
    (let [digest (byte-array length)]
      (System/arraycopy encoded 2 digest 0 length)
      (create code digest))))


(defn- read-stream-digest
  "Reads a byte digest array from an input stream. First reads a byte giving
  the length of the digest data to read. Throws an ex-info if the length is
  invalid or there is an error reading from the stream."
  ^bytes
  [^InputStream input]
  (let [length (.read input)]
    (when-not (pos? length)
      (throw (ex-info
               (format "Byte %02x is not a valid digest length." length)
               {:type :multihash/bad-input})))
    (let [digest (byte-array length)]
      (loop [offset 0
             remaining length]
        (let [n (.read input digest offset remaining)]
          (if (< n remaining)
            (recur (+ offset n) (- remaining n))
            digest))))))


(defprotocol Decodable

               (str "Cannot read multihash from byte array: " encoded-size
                    " is less than the minimum of " min-size)
               {:type :multihash/bad-input}))))
  (let [code (bytes/get-byte encoded 0)
        length (bytes/get-byte encoded 1)
        payload (- (alength encoded) 2)]
    (when-not (pos? length)
      (throw (ex-info
