forked from NeuroJSON/jsonlab
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathzlibdecode.m
40 lines (37 loc) · 1.12 KB
/
zlibdecode.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
34
35
36
37
38
39
40
function output = zlibdecode(input)
%ZLIBDECODE Decompress input bytes using ZLIB.
%
% output = zlibdecode(input)
%
% The function takes a compressed byte array INPUT and returns inflated
% bytes OUTPUT. The INPUT is a result of GZIPENCODE function. The OUTPUT
% is always an 1-by-N uint8 array. JAVA must be enabled to use the function.
%
% See also zlibencode typecast
%
% 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),0,'zlib');
return;
end
error(javachk('jvm'));
if ischar(input)
warning('zlibdecode:inputTypeMismatch', ...
'Input is char, but treated as uint8.');
input = uint8(input);
end
if ~isa(input, 'int8') && ~isa(input, 'uint8')
error('Input must be either int8 or uint8.');
end
buffer = java.io.ByteArrayOutputStream();
zlib = java.util.zip.InflaterOutputStream(buffer);
zlib.write(input, 0, numel(input));
zlib.close();
output = typecast(buffer.toByteArray(), 'uint8')';
end