       result)))
 
 (defn- process-output
+  "Writes the records to the next output file and resets the record buffer"
   [{:keys [verbose
            records
            output-folder

                 (with-open [input-stream (FileInputStream. input-file)]
                   (->> (read-source :gnucash input-stream)
                        (transduce
                          filter-record
                          process-chunk-record
                          {:output-paths []
                           :verbose (-> opts :options :verbose)
                           :records []

          (xf result record)
          result))))))

(defn- evaluate-output
  "Evaluates the output for the chunking process
  and writes the file and resets the record buffer if the
  maximum number of records has been reached"
  ([context _] (evaluate-output context))
  ([{:keys [records max-record-count] :as context}]
   (if (>= (count records) max-record-count)
     (process-output context)
     context)))

(defn- append-record
  [xf]
  (fn
    ([] (xf))
    ([context] (xf context))
    ([context record]
     (xf
       (update-in context [:records] #(conj % record))
       record))))

(defn- notify-record
  [progress-chan xf]
  (fn
    ([] (xf))
    ([context] (xf context))
    ([context record]
     (>!! progress-chan [:record record])
     (xf context record))))

(defn chunk-file
  "Accepts a path to a gnucash file and creates multiple, smaller files
