Module Js_of_ocaml_compiler.Base64
val default_alphabet : alphabet
A 64-character alphabet specifying the regular Base64 alphabet.
val uri_safe_alphabet : alphabet
A 64-character alphabet specifying the URI- and filename-safe Base64 alphabet.
val make_alphabet : string -> alphabet
Make a new alphabet.
val length_alphabet : alphabet -> int
Returns length of the alphabet, should be 64.
val alphabet : alphabet -> int array
Returns the alphabet.
val decode_exn : ?pad:bool -> ?alphabet:alphabet -> ?off:int -> ?len:int -> string -> string
decode_exn ?off ?len s
decodeslen
bytes (defaults toString.length s - off
) of the strings
starting fromoff
(defaults to0
) that is encoded in Base64 format. Will leave trailing NULLs on the string, padding it out to a multiple of 3 characters.alphabet
defaults todefault_alphabet
.pad = true
specifies to check ifs
is padded or not, otherwise, it raises an exception.Decoder can fail when character of
s
is not a part ofalphabet
or is notpadding
character. If input is not padded correctly, decoder does the best-effort but it does not ensuredecode_exn (encode ~pad:false x) = x
.- raises if
Invalid_argument
s
is not a valid Base64 string.
val decode_sub : ?pad:bool -> ?alphabet:alphabet -> ?off:int -> ?len:int -> string -> (sub, [ `Msg of string ]) result
Same as
decode_exn
but it returns a result type instead to raise an exception. Then, it returns asub
string. Decoded input(str, off, len)
will starting tooff
and will havelen
bytes - by this way, we ensure to allocate only one time result.
val decode : ?pad:bool -> ?alphabet:alphabet -> ?off:int -> ?len:int -> string -> (string, [ `Msg of string ]) result
Same as
decode_exn
, but returns an explicit error messageresult
if it fails.
val encode : ?pad:bool -> ?alphabet:alphabet -> ?off:int -> ?len:int -> string -> (string, [ `Msg of string ]) result
encode s
encodes the strings
into base64. Ifpad
is false, no trailing padding is added.pad
defaults totrue
, andalphabet
todefault_alphabet
.encode
fails whenoff
andlen
do not designate a valid range ofs
.
val encode_string : ?pad:bool -> ?alphabet:alphabet -> string -> string
encode_string s
encodes the strings
into base64. Ifpad
is false, no trailing padding is added.pad
defaults totrue
, andalphabet
todefault_alphabet
.