   (close [this] (.. this reader close)))
 
 (defn reader [f]
-  (let [rdr (DataInputStream. (BlockCompressedInputStream. (file f)))]
+  (let [data-rdr (DataInputStream. (BlockCompressedInputStream. (file f)))
+        rdr (BlockCompressedInputStream. (file f))]
     (if-not (Arrays/equals (lsb/read-bytes rdr 4) (.getBytes bam-magic))
       (throw (IOException. "Invalid BAM file header")))
     (let [header (sam/parse-header (lsb/read-string rdr (lsb/read-int rdr)))

      {:qname qname, :flag flag, :rname rname, :pos pos, :mapq  mapq,
       :cigar cigar, :rnext rnext, :pnext pnext, :tlen tlen, :seq seq,
       :qual qual, :options options})))

(defn read-alignments
  [rdr]
  (when-not (zero? (.available (.reader rdr)))
    (cons (read-alignment (.reader rdr) (.refs rdr))
          (lazy-seq (read-alignments rdr)))))

(defn- write-tag-value [writer val-type value]
  (condp = val-type

           (java.io DataInputStream DataOutputStream IOException)
           (java.nio ByteBuffer ByteOrder)
           (cljam.cigar TextCigarCodec BinaryCigarCodec CigarElement CigarOperator)
           (cljam.stream BlockCompressedInputStream BlockCompressedOutputStream)
           (cljam.bam SAMSequenceDictionary SAMSequenceRecord BAMFileIndex)))

(def fixed-block-size 32)

