Clojure equivalent of python's base64 encode and decode -


this question has answer here:

i have python code snippet , need clojure equivalent.

user_id = row.get('user_id') if user_id:     user_id_bytes = base64.urlsafe_b64decode(user_id)     creation_timestamp = int.from_bytes(user_id_bytes[:4],                                     byteorder='big')     dc_id = int.from_bytes(user_id_bytes[4:5], byteorder='big') & 31     if creation_timestamp > when_we_set_up_dc_ids:         row['dc_id'] = dc_id} 

you can use clojure's java compatibility leverage java.util.base64 class.

user> (import java.util.base64) java.util.base64  user> ;; encode message      (let [message "hello world!"            message-bytes (.getbytes message)             encoder (base64/geturlencoder)]        (.encodetostring encoder message-bytes))  "sgvsbg8gv29ybgqh"  user> ;; decode message       (let [encoded-message "sgvsbg8gv29ybgqh"             decoder (base64/geturldecoder)]         (string. (.decode decoder encoded-message))) "hello world!" 

Comments

Popular posts from this blog

unity3d - Rotate an object to face an opposite direction -

angular - Is it possible to get native element for formControl? -

javascript - Why jQuery Select box change event is now working? -