Liking cljdoc? Tell your friends :D

clj-base62

This library implements Base62 encoding and decoding in Clojure.

Should I use this?

Only if you need interoperability with an existing system that uses Base62. For new designs, just use (URL-safe) Base64. It's practically as URL-safe as Base62 - strip the padding if that's a problem - and there are performant implementations for almost every language.

Usage

There are two functions, encode and decode. encode takes a byte array and returns a base62-encoded string. decode takes a base62-encoded string and returns a byte array.

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

(base62/encode (.getBytes "Hello world!"))
;; "T8dgcjRGuYUueWht"

(String. (base62/decode "T8dgcjRGuYUueWht"))
;; "Hello world!"

Caveats

It's very slow for long inputs. By long, I mean in the order of 10 kB or bigger. You'll probably want to use Base64 or Base32.

Compatibility

The goal is to be compatible with base-x npm package.

License

Copyright Miikka Koskinen

This program and the accompanying materials are made available under the terms of the Eclipse Public License 2.0 which is available at http://www.eclipse.org/legal/epl-2.0.

This Source Code may also be made available under the following Secondary Licenses when the conditions for such availability set forth in the Eclipse Public License, v. 2.0 are satisfied: GNU General Public License as published by the Free Software Foundation, either version 2 of the License, or (at your option) any later version, with the GNU Classpath Exception which is available at https://www.gnu.org/software/classpath/license.html.

Can you improve this documentation?Edit on sourcehut

cljdoc is a website building & hosting documentation for Clojure/Script libraries

× close