cljsjs / boot-cljsjs

Helper tasks to aid the packaging of JS dependencies for Clojurescript projects
66 stars 22 forks source link

Mark is not supported #44

Closed arichiardi closed 7 years ago

arichiardi commented 7 years ago

I am trying to decompress a .gz file using the provided tasks (no tar).

Unfotunately, it blows:

...
                                             cljsjs.impl.decompress/decompress-file               decompress.clj:   26
                                             cljsjs.impl.decompress/decompress-file               decompress.clj:   29
                                                                                ...                                   
                                            cljsjs.impl.decompress/unpackage-stream               decompress.clj:   20
                                            cljsjs.impl.decompress/unpackage-stream               decompress.clj:   24
                                                                                ...                                   
org.apache.commons.compress.archivers.ArchiveStreamFactory.createArchiveInputStream    ArchiveStreamFactory.java:  290
java.lang.IllegalArgumentException: Mark is not supported.
        clojure.lang.ExceptionInfo: Mark is not supported.

Debugging it, basically the problem is that this guy creates a org.apache.commons.compress.compressors.gzip.GzipCompressorInputStream which does not support marking, which is weird.

The ArchiveStreamFactory has the requirement, see here.

Thoughts?

arichiardi commented 7 years ago

I tried to upgrade to [org.apache.commons/commons-compress "1.13"], no luck.

arichiardi commented 7 years ago

This is ugly but works (shall I PR by having a custom implementation for GZip only?):

(defn decompress-file [in out-dir & [{:keys [compression-format archive-format]}]]
  (with-open [is (if (.endsWith in ".gz")
                   (-> (io/input-stream in)
                       (try-decompress-stream {:format compression-format}))
                   (-> (io/input-stream in)
                       (try-decompress-stream {:format compression-format})
                       (unpackage-stream {:format archive-format})))]
    (if (.endsWith in ".gz")
      (let [target (io/file out-dir (.getName (io/file in)))]
        (println target)
        (io/make-parents target)
        (io/copy is target))

      (let [count (loop [i 0
                         entry (.getNextEntry is)]
                    (if entry
                      (if-not (.isDirectory entry)
                        (let [target (io/file out-dir (.getName entry))]
                          (io/make-parents target)
                                        ; After .getNextEntry the stream points to the specific archive entry
                          (io/copy is target)
                          (recur (inc i) (.getNextEntry is)))
                        (recur i (.getNextEntry is)))
                      i))]
        (util/info (format "Extracted %d files\n" count))))))

BTW I am doing this because I am trying to contribute a package and I want to minify and gz the main file and the gzipped file in one unique file if possible.