Module Brr.Base64

base64 codec.

As performed by btoa and atob functions.

Warning. These functions are slightly broken API-wise. They are easy to use incorrectly and involve a lot of data copies to use them correctly. Use only for quick hacks. The detour via the Base64.data type is provided to hopefully prevent people from shooting themselves in the foot.

Binary data

type data

The type for representing binary data to codec.

val data_utf_8_of_jstr : Jstr.t -> data

data_utf_8_of_jstr s is the UTF-16 encoded JavaScript string s as UTF-8 binary data. This is to be used with encode which results in a base64 encoding of the UTF-8 representation of s.

val data_utf_8_to_jstr : data -> (Jstr.t, Jv.Error.t) Stdlib.result

data_utf_8_to_jstr d decodes the UTF-8 binary data d to an UTF-16 encoded JavaScript string.

val data_of_binary_jstr : Jstr.t -> data

data_of_binary_jstr d is the binary data represented by the JavaScript binary string d. Note that this does not check that d is a binary string, encode will error if that's not the case. Use Tarray.to_binary_jstr to convert typed arrays to binary strings.

val data_to_binary_jstr : data -> Jstr.t

data_to_jstr d is a JavaScript binary string from d. Use Tarray.of_binary_jstr to convert binary strings to typed arrays.

Codec

val encode : data -> (Jstr.t, Jv.Error.t) Stdlib.result

encode d encodes the binary data d to base64. This errors if d was constructed with data_of_binary_jstr from an invalid JavaScript binary string.

val decode : Jstr.t -> (data, Jv.Error.t) Stdlib.result

decode s decodes the base64 encoded string s to a binary string. Errors if s is not only made of US-ASCII characters or is not well formed Base64.