@@ -81,10 +81,11 @@ The `padding` option can be one of the following:
8181 the end.
8282
8383""" .
84- -type decode_options () :: #{padding => boolean (), mode => base64_mode ()}.
84+ -type decode_options () :: #{padding => boolean (), mode => base64_mode ()}
85+ | [{padding , boolean ()} | {mode , base64_mode ()}].
8586
8687-doc """
87- Customizes the behaviour of the decode functions.
88+ Customizes the behaviour of the encode functions.
8889
8990Default value if omitted entirely or partially is ` #{mode => standard, padding => true} ` .
9091
@@ -106,7 +107,8 @@ The `padding` option can be one of the following:
106107- ** ` false ` ** - Skips appending ` = ` padding characters to the encoded string.
107108
108109""" .
109- -type encode_options () :: #{padding => boolean (), mode => base64_mode ()}.
110+ -type encode_options () :: #{padding => boolean (), mode => base64_mode ()}
111+ | [{padding , boolean ()} | {mode , base64_mode ()}].
110112
111113% % The following type is a subtype of string() for return values
112114% % of encoding functions.
@@ -274,7 +276,7 @@ Decodes a base64 string encoded using the standard alphabet according to
274276[ RFC 4648 Section 4] ( https://datatracker.ietf.org/doc/html/rfc4648#section-4 ) to
275277plain ASCII.
276278
277- The function will strips away any whitespace characters and check for the
279+ The function will strip away any whitespace characters and check for the
278280the correct number of ` = ` padding characters at the end of the encoded string.
279281
280282See ` t:decode_options/0 ` for details on which options can be passed.
@@ -317,7 +319,7 @@ Decodes a base64 "mime" string encoded using the standard alphabet according to
317319[RFC 4648 Section 4](https://datatracker.ietf.org/doc/html/rfc4648#section-4) to
318320plain ASCII.
319321
320- The function will strips away any illegal characters. It does *not* check for the
322+ The function will strip away any illegal characters. It does *not* check for the
321323the correct number of `=` padding characters at the end of the encoded string.
322324
323325See `t:decode_options/0` for details on which options can be passed.
@@ -781,11 +783,22 @@ format_error(_, _) ->
781783% % accessors
782784
783785get_padding (#{padding := Bool }) when is_boolean (Bool ) -> Bool ;
784- get_padding (#{}) -> true .
786+ get_padding (#{}) -> true ;
787+ get_padding (Opts ) when is_list (Opts ) ->
788+ case lists :keyfind (padding , 1 , Opts ) of
789+ {padding , Bool } when is_boolean (Bool ) -> Bool ;
790+ _ -> true
791+ end .
785792
786793get_decoding_offset (#{mode := standard }) -> 1 ;
787794get_decoding_offset (#{mode := urlsafe }) -> 257 ;
788- get_decoding_offset (#{}) -> 1 .
795+ get_decoding_offset (#{}) -> 1 ;
796+ get_decoding_offset (Opts ) when is_list (Opts ) ->
797+ case lists :keyfind (mode , Opts ) of
798+ {mode , standard } -> 1 ;
799+ {mode , urlsafe } -> 257 ;
800+ _ -> 1
801+ end .
789802
790803- compile ({inline , [{b64d , 2 }]}).
791804b64d (X , Off ) ->
0 commit comments