Skip to content

Commit 689cb40

Browse files
committed
support lz4 and lz4hc compression via zmat v0.9
1 parent c0cc385 commit 689cb40

File tree

7 files changed

+99
-7
lines changed

7 files changed

+99
-7
lines changed

jdatadecode.m

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -89,7 +89,7 @@
8989
if(~isempty(strmatch(N_('_ArrayZipType_'),fn)))
9090
zipmethod=data(j).(N_('_ArrayZipType_'));
9191
end
92-
if(~isempty(strmatch(zipmethod,{'zlib','gzip','lzma','lzip'})))
92+
if(~isempty(strmatch(zipmethod,{'zlib','gzip','lzma','lzip','lz4','lz4hc'})))
9393
decompfun=str2func([zipmethod 'decode']);
9494
if(needbase64)
9595
ndata=reshape(typecast(decompfun(base64decode(data(j).(N_('_ArrayZipData_')))),data(j).(N_('_ArrayType_'))),data(j).(N_('_ArrayZipSize_'))(:)');

lz4decode.m

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
function output = lz4decode(input)
2+
%LZ4DECODE Decompress input bytes using lz4.
3+
%
4+
% output = lz4decode(input)
5+
%
6+
% The function takes a compressed byte array INPUT and returns inflated
7+
% bytes OUTPUT. The INPUT is a result of LZ4DECODE function. The OUTPUT
8+
% is always an 1-by-N uint8 array.
9+
%
10+
% See also lz4encode typecast
11+
%
12+
% License : BSD, see LICENSE_*.txt
13+
%
14+
15+
if(nargin==0)
16+
error('you must provide at least 1 input');
17+
end
18+
if(exist('zmat','file')==2 || exist('zmat','file')==3)
19+
output=zmat(uint8(input),0,'lz4');
20+
return;
21+
else
22+
error('you must install ZMat toolbox to use this feature: http://github.com/fangq/zmat')
23+
end

lz4encode.m

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
function output = lz4encode(input)
2+
%LZ4ENCODE Compress input bytes with lz4.
3+
%
4+
% output = lz4encode(input)
5+
%
6+
% The function takes a char, int8, or uint8 array INPUT and returns
7+
% compressed bytes OUTPUT as a uint8 array. Note that the compression
8+
% doesn't preserve input dimensions.
9+
%
10+
% See also lz4decode
11+
%
12+
% License : BSD, see LICENSE_*.txt
13+
%
14+
15+
if(nargin==0)
16+
error('you must provide at least 1 input');
17+
end
18+
if(exist('zmat','file')==2 || exist('zmat','file')==3)
19+
output=zmat(uint8(input),1,'lz4');
20+
return;
21+
else
22+
error('you must install ZMat toolbox to use this feature: http://github.com/fangq/zmat')
23+
end

lz4hcdecode.m

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
function output = lz4hcdecode(input)
2+
%LZ4HCDECODE Decompress input bytes using lz4hc.
3+
%
4+
% output = lz4hcdecode(input)
5+
%
6+
% The function takes a compressed byte array INPUT and returns inflated
7+
% bytes OUTPUT. The INPUT is a result of LZ4HCDECODE function. The OUTPUT
8+
% is always an 1-by-N uint8 array.
9+
%
10+
% See also lz4hcencode typecast
11+
%
12+
% License : BSD, see LICENSE_*.txt
13+
%
14+
15+
if(nargin==0)
16+
error('you must provide at least 1 input');
17+
end
18+
if(exist('zmat','file')==2 || exist('zmat','file')==3)
19+
output=zmat(uint8(input),0,'lz4hc');
20+
return;
21+
else
22+
error('you must install ZMat toolbox to use this feature: http://github.com/fangq/zmat')
23+
end

lz4hcencode.m

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
function output = lz4hcencode(input)
2+
%LZ4HCENCODE Compress input bytes with lz4hc.
3+
%
4+
% output = lz4hcencode(input)
5+
%
6+
% The function takes a char, int8, or uint8 array INPUT and returns
7+
% compressed bytes OUTPUT as a uint8 array. Note that the compression
8+
% doesn't preserve input dimensions.
9+
%
10+
% See also lz4hcdecode
11+
%
12+
% License : BSD, see LICENSE_*.txt
13+
%
14+
15+
if(nargin==0)
16+
error('you must provide at least 1 input');
17+
end
18+
if(exist('zmat','file')==2 || exist('zmat','file')==3)
19+
output=zmat(uint8(input),1,'lz4hc');
20+
return;
21+
else
22+
error('you must install ZMat toolbox to use this feature: http://github.com/fangq/zmat')
23+
end

savejson.m

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -67,8 +67,8 @@
6767
% back to the string form
6868
% opt.SaveBinary [0|1]: 1 - save the JSON file in binary mode; 0 - text mode.
6969
% opt.Compact [0|1]: 1- out compact JSON format (remove all newlines and tabs)
70-
% opt.Compression 'zlib', 'gzip', 'lzma' or 'lzip': specify array compression
71-
% method; currently only supports 4 methods. The
70+
% opt.Compression 'zlib', 'gzip', 'lzma', 'lzip', 'lz4' or 'lz4hc': specify array
71+
% compression method; currently only supports 6 methods. The
7272
% data compression only applicable to numerical arrays
7373
% in 3D or higher dimensions, or when ArrayToStruct
7474
% is 1 for 1D or 2D arrays. If one wants to
@@ -131,7 +131,7 @@
131131

132132
dozip=jsonopt('Compression','',opt);
133133
if(~isempty(dozip))
134-
if(isempty(strmatch(dozip,{'zlib','gzip','lzma','lzip'})))
134+
if(isempty(strmatch(dozip,{'zlib','gzip','lzma','lzip','lz4','lz4hc'})))
135135
error('compression method "%s" is not supported',dozip);
136136
end
137137
if(exist('zmat','file')~=2 && exist('zmat','file')~=3)

saveubjson.m

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -61,8 +61,8 @@
6161
% wrapped inside a function call as 'foo(...);'
6262
% opt.UnpackHex [1|0]: conver the 0x[hex code] output by loadjson
6363
% back to the string form
64-
% opt.Compression 'zlib', 'gzip', 'lzma' or 'lzip': specify array compression
65-
% method; currently only supports 4 methods. The
64+
% opt.Compression 'zlib', 'gzip', 'lzma', 'lzip', 'lz4' or 'lz4hc': specify array
65+
% compression method; currently only supports 6 methods. The
6666
% data compression only applicable to numerical arrays
6767
% in 3D or higher dimensions, or when ArrayToStruct
6868
% is 1 for 1D or 2D arrays. If one wants to
@@ -129,7 +129,7 @@
129129

130130
dozip=jsonopt('Compression','',opt);
131131
if(~isempty(dozip))
132-
if(isempty(strmatch(dozip,{'zlib','gzip','lzma','lzip'})))
132+
if(isempty(strmatch(dozip,{'zlib','gzip','lzma','lzip','lz4','lz4hc'})))
133133
error('compression method "%s" is not supported',dozip);
134134
end
135135
if(exist('zmat','file')~=2 && exist('zmat','file')~=3)

0 commit comments

Comments
 (0)