Last active
October 5, 2015 07:41
-
-
Save goldobin/5d845ba9df5680597ff5 to your computer and use it in GitHub Desktop.
Base64 codecs for Scala (JDK8)
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
object Base64Codecs { | |
private val base64Encoder = Base64.getEncoder | |
private val base64Decoder = Base64.getDecoder | |
private def toBase64String(bytes: Array[Byte]): String = { | |
base64Encoder.encodeToString(bytes) | |
} | |
private def parseBase64String(s: String): Array[Byte] = { | |
base64Decoder.decode(s) | |
} | |
implicit class StringWithBase64Methods(s: String) { | |
def decodeBase64: ByteString = ByteString(base64Decoder.decode(s)) | |
} | |
implicit class ByteSeqWithMethods(s: Seq[Byte]) { | |
def encodeBase64: String = base64Encoder.encodeToString(s.toArray) | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment