       validity
       reader
       #(doseq [file %]
-         (let [json-filename ^String (json-filename-fn)
+         (let [json-filename ^String (fs/json-filename original-filename)
                compressed-file (fs/create-target-file json-filename)]
+           (log/debug "Saving result as" json-filename)
            (with-open [output-stream (io/output-stream compressed-file)
                        zip (ZipOutputStream. output-stream)]
              (.putNextEntry zip (ZipEntry. json-filename))


(defn- translate-file-from-zipentry [dataset, mapping, validity, ^ZipFile zipfile, ^ZipEntry entry]
  "Transform a single entry in a zip-file. Returns the location where the result is saved on the filesystem"
  (let [json-filename-fn #(let [json-filename (fs/json-filename (.getName (File. (.getName entry))))]
                            (log/debug "Saving result as" json-filename)
                            json-filename)
        entry-stream (.getInputStream zipfile entry)]
    (log/debug "Going to transform zip entry" (.getName entry))
    (let [resulting-files (translate-file-from-stream entry-stream dataset mapping validity json-filename-fn)]
      (.close entry-stream)
      resulting-files)))


  "Transforms a file or zip-stream and returns a vector with the transformed files"
  (if (= format :zip)
    (translate-from-zipfile file dataset mapping validity)
    (do
      (log/debug "Going to transform file" original-filename)
      (with-open [stream (condp = format
                           :gzip (GZIPInputStream. (FileInputStream. file))
                           :plain (FileInputStream. file))]
        (translate-file-from-stream stream dataset mapping validity original-filename)))))

(defn extract-filename [headers, ^String uri]
  "Extract the original filename from the Content-Disposition header, or from the URI if unavailable"
