Skip to content

Commit

Permalink
road to bb: Use JDK Base64 decoding support
Browse files Browse the repository at this point in the history
Closes #416

Contributes to #380
  • Loading branch information
lread committed May 22, 2022
1 parent e324a3b commit a4a1398
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 5 deletions.
3 changes: 1 addition & 2 deletions project.clj
Original file line number Diff line number Diff line change
Expand Up @@ -39,8 +39,7 @@
[clj-http "3.10.1"]
[cheshire "5.9.0"]
[org.clojure/tools.cli "1.0.194"]
[org.clojure/tools.logging "0.3.1"]
[org.clojure/data.codec "0.1.0"]]
[org.clojure/tools.logging "0.3.1"]]

:test-selectors {:unit :unit}

Expand Down
9 changes: 6 additions & 3 deletions src/etaoin/api.clj
Original file line number Diff line number Diff line change
Expand Up @@ -25,15 +25,14 @@
[etaoin.driver :as drv]
[etaoin.xpath :as xpath]

[clojure.data.codec.base64 :as b64]
[clojure.tools.logging :as log]
[clojure.java.io :as io]
[clojure.string :as str]

[cheshire.core :refer [generate-stream]]
[slingshot.slingshot :refer [try+ throw+]])

(:import java.util.Date
(:import (java.util Date Base64)
java.text.SimpleDateFormat))

;;
Expand Down Expand Up @@ -2950,6 +2949,10 @@
;; screenshots
;;

(defn- b64-decode [s]
(-> (Base64/getDecoder)
(.decode s)))

(defmulti ^:private b64-to-file
"Dumps a Base64-encoded string into a file.
A file might be either a path or a `java.io.File` instance."
Expand All @@ -2965,7 +2968,7 @@
[String String]
[^String b64str filepath]
(with-open [out (io/output-stream filepath)]
(.write out ^bytes (b64/decode (.getBytes b64str)))))
(.write out ^bytes (b64-decode b64str))))

(defmulti screenshot
"Takes a screenshot of the current page. Saves it in a *.png file on disk.
Expand Down

0 comments on commit a4a1398

Please sign in to comment.