Base64

Base64 encoder / decoder

License

License

BSD
GroupId

GroupId

com.github.marklister
ArtifactId

ArtifactId

base64_2.12
Last Version

Last Version

0.3.0
Release Date

Release Date

Type

Type

jar
Description

Description

Base64
Base64 encoder / decoder
Project URL

Project URL

https://github.com/marklister/base64
Project Organization

Project Organization

com.github.marklister
Source Code Management

Source Code Management

https://github.com/marklister/base64

Download base64_2.12

How to add to project

<!-- https://jarcasting.com/artifacts/com.github.marklister/base64_2.12/ -->
<dependency>
    <groupId>com.github.marklister</groupId>
    <artifactId>base64_2.12</artifactId>
    <version>0.3.0</version>
</dependency>
// https://jarcasting.com/artifacts/com.github.marklister/base64_2.12/
implementation 'com.github.marklister:base64_2.12:0.3.0'
// https://jarcasting.com/artifacts/com.github.marklister/base64_2.12/
implementation ("com.github.marklister:base64_2.12:0.3.0")
'com.github.marklister:base64_2.12:jar:0.3.0'
<dependency org="com.github.marklister" name="base64_2.12" rev="0.3.0">
  <artifact name="base64_2.12" type="jar" />
</dependency>
@Grapes(
@Grab(group='com.github.marklister', module='base64_2.12', version='0.3.0')
)
libraryDependencies += "com.github.marklister" % "base64_2.12" % "0.3.0"
[com.github.marklister/base64_2.12 "0.3.0"]

Dependencies

compile (1)

Group / Artifact Type Version
org.scala-lang : scala-library jar 2.12.12

test (1)

Group / Artifact Type Version
com.lihaoyi : utest_2.12 jar 0.7.5

Project Modules

There are no modules declared in this project.

Base64

Another Base64 encoder / decoder.

This one is

  • really small
  • not very efficient (the latest version is not too bad)
  • liberal license (BSD)*,
  • simple API
  • idiomatic scala, and
  • need not add a dependency to your project. Just copy the one source file to your project.
  • Scala-js compatible
  • no Dom required
  • works on client or server

Getting Started

Using SBT:

libraryDependencies += "com.github.marklister" %% "base64" % "0.3.0"

or for scala-js

libraryDependencies += "com.github.marklister" %%% "base64" % "0.3.0"

API

Simply invoke toBase64 on an Array[Byte] or Seq[Byte] or ArrayBuffer[Byte] or

toByteArray on a String containing a Base64 representation.

Imports

import com.github.marklister.base64.Base64.Encoder 
import com.github.marklister.base64.Base64.Decoder

or use a wildcard:

import com.github.marklister.base64.Base64._

Base64 Url

Two encoding schemes are provided as default: base64 and base64Url. base64 is the default one. To select base64Url

Using implicits -- just make the encode/decode scheme available via an implicit:

implicit val encoding = base64Url

Or you can provide the scheme as an argument to toByteArray or toBase64 eg toBase64(base64Url) or toByteArray(base64)

Padding

Padding is strict for the base64 encode scheme and non-strict for base64Url

To create a non strict scheme:

implicit val encoding = base64.copy(strictPadding=false)

Efficiency

This implementation began life as a toy implementation that chose simplicity over efficiency. The advent of scalaJs meant that the library has a real world target and warranted improving its efficiency. Version 0.2.1 improves efficiency greatly but some legacy inefficiencies remain.

REPL example

[info] Starting scala interpreter...
[info] 
import com.github.marklister.base64.Base64._
Welcome to Scala version 2.10.2 (OpenJDK Server VM, Java 1.7.0_51).
Type in expressions to have them evaluated.
Type :help for more information.

scala> "ABCDEFG".getBytes.toBase64 //Encodes Array[Byte]=>String
res0: String = QUJDREVGRw==

scala> res0.toByteArray //Decodes base64 String=>Array[Byte]
res1: Array[Byte] = Array(65, 66, 67, 68, 69, 70, 71)

scala> res1.sameElements("ABCDEFG".getBytes)
res2: Boolean = true
  • At one stage this code was released as public domain but there was some discussion about the validity of public domain licences and they don't work on Maven Central. So now it's BSD. If you need some other licence then raise an issue.

Versions

Version
0.3.0
0.2.10
0.2.9
0.2.6
0.2.5
0.2.4
0.2.3