clj-commons / byte-streams

A Rosetta stone for JVM byte representations
417 stars 33 forks source link

`:tag` metadata can be wrong #45

Closed vemv closed 3 years ago

vemv commented 3 years ago

:tag metadata should denote classes or primitives - not arbitrary objects.

However some of the :tags that byte-streams emits can denote byte_streams.graph.Type objects:

(in-ns 'byte-streams)

;; inspect the def-transfer defined at https://github.com/clj-commons/byte-streams/blob/4066d637300c144d37e888c23de1a9c3ae19829a/src/byte_streams.clj#L610 :
(-> '(def-transfer [ReadableByteChannel File]
       [channel file {:keys [chunk-size] :or {chunk-size (int 1e7)} :as options}]
       (let [^FileChannel fc (convert file WritableByteChannel options)]
         (try
           (loop [idx 0]
             (let [n (.transferFrom fc channel idx chunk-size)]
               (when (pos? n)
                 (recur (+ idx n)))))
           (finally
             (.force fc true)
             (.close fc)))))
    macroexpand-1
    last
    second
    second
    meta
    println)

;; {:tag #object[byte_streams.graph.Type 0x62e58f04 java.io.File]}

...this is accurately reported by running lein eastwood.

Fixing this might also solve other tag-related issues that I can see in the tracker.

Hope it helps!

-V