aboutsummaryrefslogtreecommitdiff
path: root/src/jlib.erl
diff options
context:
space:
mode:
Diffstat (limited to 'src/jlib.erl')
-rw-r--r--src/jlib.erl16
1 files changed, 16 insertions, 0 deletions
diff --git a/src/jlib.erl b/src/jlib.erl
index a362697f4..ffabb3ffe 100644
--- a/src/jlib.erl
+++ b/src/jlib.erl
@@ -46,6 +46,7 @@
timestamp_to_iso/2, timestamp_to_xml/4,
timestamp_to_xml/1, now_to_utc_string/1,
now_to_local_string/1, datetime_string_to_timestamp/1,
+ term_to_base64/1, base64_to_term/1,
decode_base64/1, encode_base64/1, ip_to_list/1,
rsm_encode/1, rsm_encode/2, rsm_decode/1,
binary_to_integer/1, binary_to_integer/2,
@@ -780,6 +781,21 @@ check_list(List) ->
% Base64 stuff (based on httpd_util.erl)
%
+-spec term_to_base64(term()) -> binary().
+
+term_to_base64(Term) ->
+ encode_base64(term_to_binary(Term)).
+
+-spec base64_to_term(binary()) -> {term, term()} | error.
+
+base64_to_term(Base64) ->
+ case catch binary_to_term(decode_base64(Base64), [safe]) of
+ {'EXIT', _} ->
+ error;
+ Term ->
+ {term, Term}
+ end.
+
-spec decode_base64(binary()) -> binary().
decode_base64(S) ->