Created
September 3, 2012 15:56
-
-
Save jcromartie/3610244 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
(ns | |
^{:author "John Cromartie" | |
:doc "A library for reading and writing gzip-compressed data"} | |
cljz.core | |
(:refer-clojure :exclue [spit slurp]) | |
(require [clojure.java.io :as io]) | |
(import [java.util.zip GZIPInputStream GZIPOutputStream])) | |
(defn input-stream | |
[x & opts] | |
(GZIPInputStream. (apply io/input-stream x opts))) | |
(defn output-stream | |
[x & opts] | |
(GZIPOutputStream. (apply io/output-stream x opts))) | |
(defn reader | |
[x & opts] | |
(apply io/reader (input-stream x) opts)) | |
(defn writer | |
[x & opts] | |
(apply io/writer (output-stream x) opts)) | |
(defn spit | |
[f content] | |
(with-open [w (writer f)] | |
(.write w (str content)))) | |
(defn slurp | |
[f] | |
(with-open [r (reader f)] | |
(let [sb (StringBuilder.)] | |
(loop [c (.read r)] | |
(if (neg? c) | |
(str sb) | |
(do | |
(.append sb (char c)) | |
(recur (.read r)))))))) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment