Skip to content

xsc/base64-clj

Repository files navigation

base64-clj

Convert Data to Base64 and back in a reasonable amount of time.

Build Status endorse

This is at least as fast as the Apache Commons Base64 Codec (whose just-as-simple usage you can see here), but slower than Alexander Taggart's data.codec.

Usage

Leiningen

[base64-clj "0.1.1"]

REPL

(require '[base64-clj.core :as base64])

(base64/encode "Hello, World!")
;; => "SGVsbG8sIFdvcmxkIQ=="
(base64/decode "SGVsbG8sIFdvcmxkIQ==")
;; => "Hello, World!"

(base64/encode-bytes (.getBytes "Hello, World!"))
;; => #<byte[] [B@28a34522>
(base64/decode-bytes (.getBytes "SGVsbG8sIFdvcmxkIQ=="))
;; => #<byte[] [B@18b0af83>

(base64/encode "ÄÖÜ" "ISO-8859-1")
;; => "xNbc"
(base64/encode "ÄÖÜ" "UTF-8")
;; => "w4TDlsOc"

(base64/decode "xNbc")
;; => "???"
(base64/decode "xNbc" "ISO-8859-1")
;; => "ÄÖÜ"

Tests

You can run Midje tests using the following Leiningen command:

lein midje

Benchmarks

You can run Criterium benchmarks on different Base64 codecs with the following Leiningen command:

lein benchmark base64-clj-benchmark.<ID> [--quick]

ID is one of:

  • base64-clj : evaluate this project
  • base64-naive : evaluate a naive and intuitive implementation
  • apache-commons-base64 : evaluate the Apache Commons Codec
  • clojure-data-codec : evaluate clojure.data.codec.base64

License

Copyright © Yannick Scherer

Distributed under the Eclipse Public License, the same as Clojure.

About

Fast Base64 Encoding/Decoding for Clojure

Resources

Stars

Watchers

Forks

Packages

No packages published