Posts Tagged ‘gzip’

Gunzipping files with Clojure

Posted: February 17, 2012 in Clojure, Lisp
Tags: ,

This is just a quicky that might be useful to others, too. The following function unzips the input to the output.

Update: As Ben pointed out, tis will only work correctly for gzipped text files encoded in UTF-8 as input (ASCII, ISO-5589-1 will also be fine).

(ns foobar
  (:require [ :as io]))

(defn gunzip
  [fi fo]
  (with-open [i (io/reader
                  (io/input-stream fi)))
              o ( (io/writer fo))]
    (doseq [l (line-seq i)]
      (.println o l))))