Created
December 22, 2017 23:40
-
-
Save mujahidk/7fdda0c69d11fc3e4a0907ce4ea77537 to your computer and use it in GitHub Desktop.
Base64 encoding and decoding in Groovy.
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
def text = "Going to convert this to Base64 encoding!" | |
// Encode | |
def encoded = text.bytes.encodeBase64().toString() | |
println encoded | |
// Decode | |
byte[] decoded = encoded.decodeBase64() | |
println new String(decoded) |
Author
mujahidk
commented
Oct 29, 2019
via email
It depends on what the encoded text contains. For example base64 could contain a jpeg image or zip file. Basically decode returns you byte array, try saving that to a file when you know what it contains.
…Sent from my iPhone
On Oct 28, 2019, at 6:41 AM, Sevastyan Savanyuk ***@***.***> wrote:
How to decode base64 to binary file?
—
You are receiving this because you authored the thread.
Reply to this email directly, view it on GitHub, or unsubscribe.
Got it working. Thanks.
def binaryFile = file("pathToBinaryFile")
file("pathToBase64EncodedContent").withInputStream { input ->
binaryFile.withOutputStream { output ->
output.write(Base64.decoder.decode(input.text))
}
}
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment