Skip to content

Commit

Permalink
add io/byteslurp
Browse files Browse the repository at this point in the history
  • Loading branch information
apage43 committed Sep 10, 2012
1 parent 2da8223 commit c680229
Showing 1 changed file with 11 additions and 0 deletions.
11 changes: 11 additions & 0 deletions src/grab_bag/io.clj
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
(ns grab-bag.io
(:require [clojure.java.io :as io]))

(defn byteslurp
"Like slurp but returns a byte[]"
[file]
(let [bs (transient [])]
(with-open [istream (io/input-stream file)]
(loop [b (.read istream)]
(if (neg? b) (byte-array (persistent! bs))
(do (conj! bs (.byteValue b)) (recur (.read istream))))))))

0 comments on commit c680229

Please sign in to comment.