feat(emqx_rule_funcs): add functions gzip, gunzip, zip, unzip
This commit is contained in:
parent
e4b5001a57
commit
62eff94249
|
@ -169,6 +169,16 @@
|
|||
, sha256/1
|
||||
]).
|
||||
|
||||
%% gzip Funcs
|
||||
-export([ gzip/1
|
||||
, gunzip/1
|
||||
]).
|
||||
|
||||
%% zip Funcs
|
||||
-export([ zip/1
|
||||
, unzip/1
|
||||
]).
|
||||
|
||||
%% Data encode and decode
|
||||
-export([ base64_encode/1
|
||||
, base64_decode/1
|
||||
|
@ -784,6 +794,26 @@ sha256(S) when is_binary(S) ->
|
|||
hash(Type, Data) ->
|
||||
emqx_misc:bin2hexstr_a_f(crypto:hash(Type, Data)).
|
||||
|
||||
%%------------------------------------------------------------------------------
|
||||
%% gzip Funcs
|
||||
%%------------------------------------------------------------------------------
|
||||
|
||||
gzip(S) when is_binary(S) ->
|
||||
zlib:gzip(S).
|
||||
|
||||
gunzip(S) when is_binary(S) ->
|
||||
zlib:gunzip(S).
|
||||
|
||||
%%------------------------------------------------------------------------------
|
||||
%% zip Funcs
|
||||
%%------------------------------------------------------------------------------
|
||||
|
||||
zip(S) when is_binary(S) ->
|
||||
zlib:zip(S).
|
||||
|
||||
unzip(S) when is_binary(S) ->
|
||||
zlib:unzip(S).
|
||||
|
||||
%%------------------------------------------------------------------------------
|
||||
%% Data encode and decode Funcs
|
||||
%%------------------------------------------------------------------------------
|
||||
|
|
|
@ -609,6 +609,29 @@ prop_hash_fun() ->
|
|||
(64 == byte_size(apply_func(sha256, [S])))
|
||||
end).
|
||||
|
||||
|
||||
%%------------------------------------------------------------------------------
|
||||
%% Test cases for gzip funcs
|
||||
%%------------------------------------------------------------------------------
|
||||
|
||||
t_gzip_funcs(_) ->
|
||||
?PROPTEST(prop_gzip_fun).
|
||||
|
||||
prop_gzip_fun() ->
|
||||
?FORALL(S, binary(),
|
||||
S == apply_func(gunzip, [apply_func(gzip, [S])])).
|
||||
|
||||
%%------------------------------------------------------------------------------
|
||||
%% Test cases for zip funcs
|
||||
%%------------------------------------------------------------------------------
|
||||
|
||||
t_zip_funcs(_) ->
|
||||
?PROPTEST(prop_zip_fun).
|
||||
|
||||
prop_zip_fun() ->
|
||||
?FORALL(S, binary(),
|
||||
S == apply_func(unzip, [apply_func(zip, [S])])).
|
||||
|
||||
%%------------------------------------------------------------------------------
|
||||
%% Test cases for base64
|
||||
%%------------------------------------------------------------------------------
|
||||
|
@ -822,4 +845,3 @@ all() ->
|
|||
|
||||
suite() ->
|
||||
[{ct_hooks, [cth_surefire]}, {timetrap, {seconds, 30}}].
|
||||
|
||||
|
|
Loading…
Reference in New Issue