Skip to content

Instantly share code, notes, and snippets.

@blakesmith
Created December 6, 2011 16:36
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save blakesmith/1438863 to your computer and use it in GitHub Desktop.
Save blakesmith/1438863 to your computer and use it in GitHub Desktop.
(defn read-bytes [input-stream n]
(loop [coll [] bytes-read 0]
(let [next-byte (.read input-stream)]
(if (or (= next-byte -1) (= bytes-read n))
coll
(recur (conj coll next-byte) (inc bytes-read))))))
user=> (read-bytes is 3)
[99 104 112]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment