Here’s the translation of the Base64 Encoding example from Go to PureScript:
PureScript provides support for base64 encoding/decoding through the purescript-node-buffer and purescript-encoding libraries.
To run this program, you’ll need to install the necessary dependencies:
Then you can compile and run the program:
The string encodes to slightly different values with the standard and URL base64 encoders (trailing + vs -) but they both decode to the original string as desired.
Note that PureScript, being a purely functional language, handles effects and potential errors differently from imperative languages. We use the Effect monad to handle side effects, and the Either type to handle potential decoding errors.
The Buffer module from purescript-node-buffer is used for byte-level operations, which is necessary for base64 encoding and decoding. The Encoding type from purescript-node-encoding provides the different encoding options, including Base64 and Base64URL.