This module contains helper functions for working with binaries.
To use this module, you must import it to your DataWeave code, for example,
by adding the line import * from dw::core::Binaries
to the header of your
DataWeave script.
Functions
fromBase64
fromBase64(String): Binary
Transforms a Base64 string to binary.
Parameters
Name | Description |
---|---|
|
The Base64 string to transform. |
Example
This example takes a Base64 string and transforms it to binary.
Source
1
2
3
4
5
%dw 2.0
import * from dw::core::Binaries
output application/json
---
{ "BinaryFromBase64" : fromBase64("TXVsZQ==") }
Output
1
{ "BinaryFromBase64": "Mule" }
fromHex
fromHex(String): Binary
Transforms an hexadecimal string into a binary.
Parameters
Name | Description |
---|---|
|
A hexadecimal string to transform. |
Example
This example transforms a hexadecimal string to "Mule".
Source
1
2
3
4
5
%dw 2.0
import * from dw::core::Binaries
output application/json
---
{ "hexToBinary": fromHex("4D756C65") }
Output
1
{ "hexToBinary": "Mule" }
toBase64
toBase64(Binary): String
Transforms a binary value a Base64 string.
Parameters
Name | Description |
---|---|
|
The binary value to transform. |
Example
This example transforms a binary to Base64.
Source
1
2
3
4
5
6
%dw 2.0
import * from dw::core::Binaries
var myBinary = "Mule" as Binary
output application/json
---
{ "BinaryToBase64" : toBase64(myBinary) }
Output
1
{ "BinaryToBase64": "TXVsZQ==" }
toHex
toHex(Binary): String
Transforms a binary value into the hexadecimal string.
Parameters
Name | Description |
---|---|
|
The |
Example
This example transforms a binary version of "Mule" (defined in the variable,
myBinary
) to hexadecimal.
Source
1
2
3
4
5
6
7
8
9
%dw 2.0
import * from dw::core::Binaries
output application/json
var myBinary = "Mule" as Binary
var testType = typeOf(myBinary)
---
{
"binaryToHex" : toHex(myBinary)
}
Output
1
{ "binaryToHex": "4D756C65" }