forked from NeuroJSON/jsonlab
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathbase64encode.m
33 lines (31 loc) · 954 Bytes
/
base64encode.m
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
function output = base64encode(input)
%BASE64ENCODE Encode a byte array using Base64 codec.
%
% output = base64encode(input)
%
% The function takes a char, int8, or uint8 array INPUT and returns Base64
% encoded string OUTPUT. JAVA must be running to use this function. Note
% that encoding doesn't preserve input dimensions.
%
% See also base64decode
%
% Copyright (c) 2012, Kota Yamaguchi
% URL: https://www.mathworks.com/matlabcentral/fileexchange/39526-byte-encoding-utilities
% License : BSD, see LICENSE_*.txt
%
if(nargin==0)
error('you must provide at least 1 input');
end
if(exist('zmat')==3)
output=zmat(uint8(input),1,'base64');
return;
end
if(exist('OCTAVE_VERSION','builtin'))
output = base64_encode(uint8(input));
return;
end
error(javachk('jvm'));
if ischar(input), input = uint8(input); end
output = char(org.apache.commons.codec.binary.Base64.encodeBase64Chunked(input))';
output = regexprep(output,'\r','');
end