Skip to content

Instantly share code, notes, and snippets.

@tonsky
Created January 3, 2013 09:05
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 tonsky/4442030 to your computer and use it in GitHub Desktop.
Save tonsky/4442030 to your computer and use it in GitHub Desktop.
(def ^:dynamic chunk-size 17)
(defn next-chunk [rdr]
(let [buf (char-array chunk-size)
s (.read rdr buf)]
(when (pos? s)
(java.nio.CharBuffer/wrap buf 0 s))))
(defn chunk-seq [rdr]
(when-let [chunk (next-chunk rdr)]
(cons chunk (lazy-seq (chunk-seq rdr)))))
(with-open [rdr (clojure.java.io/reader "/Users/prokopov/.profile")]
(doseq [chunk (chunk-seq rdr)]
(println "Read" (.remaining chunk) "bytes:" (str chunk))))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment