clj-digest / src / digest.clj

Diff from to

File src/digest.clj

   #^{ :author "Miki Tebeka <>"
       :doc "Message digest algorithms for Clojure"}
   (:use [clojure.string :only (split lower-case)])
-  (:import ( MessageDigest Security)
+  (:import java.util.Arrays
+           ( MessageDigest Security)
            ( FileInputStream File InputStream)))
 ; Default buffer size for reading
 (def *buffer-size* 1024)
+; Why on earth is private?
 (def ByteArray (type (make-array Byte/TYPE 0)))
 (defn- read-some 
   (let [buffer (make-array Byte/TYPE *buffer-size*)
         size (.read reader buffer)]
-    (when (> size 0) [buffer size])))
+    (when (> size 0)
+      (if (= size *buffer-size*) buffer (Arrays/copyOf buffer size)))))
 (defn- byte-seq
   "Return a sequence of [data size] from reader."
   (digest algorithm (.getBytes message)))
 (defmethod digest ByteArray [algorithm message]
-  (digest algorithm [[message (count message)]]))
+  (digest algorithm [message]))
 (defmethod digest File [algorithm file]
   (digest algorithm (FileInputStream. file)))
 (defmethod digest :default [algorithm chunks]
   (let [algo (MessageDigest/getInstance algorithm)]
     (.reset algo)
-    (dorun (map (fn [[message size]] (.update algo message 0 size)) chunks))
+    (dorun (map #(.update algo %) chunks))
     (.toString (BigInteger. 1 (.digest algo)) 16)))
 (defn algorithms []