Miki Tebeka committed 3a1f949

Simpler byte-seq

Comments (0)

Files changed (3)

 * byte array
-* Sequence of [byte-array size]
+* Sequence of byte array
-Add `[digest "1.1.0"]` to your `project.clj`
+Add `[digest "1.2.0"]` to your `project.clj`
-(defproject digest "1.1.1"
+(defproject digest "1.2.0"
   :description "Digest algorithms (MD5, SHA ...) for Clojure"
   :author "Miki Tebeka <>"
   :url ""
   #^{ :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 []
Tip: Filter by directory path e.g. /media app.js to search for public/media/app.js.
Tip: Use camelCasing e.g. ProjME to search for
Tip: Filter by extension type e.g. /repo .js to search for all .js files in the /repo directory.
Tip: Separate your search with spaces e.g. /ssh pom.xml to search for src/ssh/pom.xml.
Tip: Use ↑ and ↓ arrow keys to navigate and return to view the file.
Tip: You can also navigate files with Ctrl+j (next) and Ctrl+k (previous) and view the file with Ctrl+o.
Tip: You can also navigate files with Alt+j (next) and Alt+k (previous) and view the file with Alt+o.