Guest User

Untitled

a guest
Apr 21st, 2018
83
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.68 KB | None | 0 0
  1. (defn- jar-stream-seq [stream]
  2. (take-while #(not= nil %) (repeatedly #(.getNextEntry stream))))
  3.  
  4. (defn- create-parent [archive-entry]
  5. (-> archive-entry (.getParentFile) (.mkdirs)))
  6.  
  7. (defn- extract-entry [entry dir jar-stream]
  8. (let [archive-entry (file dir (.getName entry))]
  9. (create-parent archive-entry)
  10. (cond (.isDirectory entry) (.mkdir archive-entry)
  11. :else (with-open [fos (FileOutputStream. archive-entry)]
  12. (copy jar-stream fos)))))
  13.  
  14. (defn unjar [src dest]
  15. (with-open [jar-stream (JarArchiveInputStream. (file-in-stream (file-str src)))]
  16. (let [dir (file dest)]
  17. (doseq [entry (jar-stream-seq jar-stream)] (extract-entry entry dir jar-stream)))))
Add Comment
Please, Sign In to add comment