From a4a1398bb4247a028bd9c5e722940b6381973d7c Mon Sep 17 00:00:00 2001 From: lread Date: Sun, 22 May 2022 11:43:03 -0400 Subject: [PATCH] road to bb: Use JDK Base64 decoding support Closes #416 Contributes to #380 --- project.clj | 3 +-- src/etaoin/api.clj | 9 ++++++--- 2 files changed, 7 insertions(+), 5 deletions(-) diff --git a/project.clj b/project.clj index 4495dde0..123aa441 100644 --- a/project.clj +++ b/project.clj @@ -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} diff --git a/src/etaoin/api.clj b/src/etaoin/api.clj index c4d01137..75765245 100644 --- a/src/etaoin/api.clj +++ b/src/etaoin/api.clj @@ -25,7 +25,6 @@ [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] @@ -33,7 +32,7 @@ [cheshire.core :refer [generate-stream]] [slingshot.slingshot :refer [try+ throw+]]) - (:import java.util.Date + (:import (java.util Date Base64) java.text.SimpleDateFormat)) ;; @@ -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." @@ -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.