|
1 | | -function varargout=octavezz(data, iscompress, zipmethod) |
| 1 | +function varargout=octavezmat(data, iscompress, zipmethod) |
2 | 2 | % |
3 | | -% output = octavezz(input, iscompress, zipmethod) |
| 3 | +% output = octavezmat(input, iscompress, zipmethod) |
4 | 4 | % or |
5 | | -% [output, info] = octavezz(input, iscompress, zipmethod) |
6 | | -% unzipdata = octavezz(zipdata, info) |
| 5 | +% [output, info] = octavezmat(input, iscompress, zipmethod) |
| 6 | +% unzipdata = octavezmat(zipdata, info) |
7 | 7 | % |
8 | 8 | % Compress or decompress zlib and gzip memory buffers using zip/unzip/gzip/gunzip on Octave |
9 | | -% in case ZMat toolbox (http://github.com/NeuroJSON/zmat) was not installed (ZMat will be much faster) |
| 9 | +% in case ZMat toolbox (http://github.com/NeuroJSON/zmat) was not installed (ZMat is much faster) |
10 | 10 | % |
11 | | -% Copyright (c) 2023, Qianqian Fang (q.fang <at> neu.edu) |
| 11 | +% Author: Qianqian Fang (q.fang <at> neu.edu) |
12 | 12 | % |
13 | 13 | % input: |
14 | 14 | % input: the input data (can be either compressed or before compression), |
|
46 | 46 | % level, see above |
47 | 47 | % |
48 | 48 | % examples: |
49 | | -% [ss,info]=octavezz(ones(10)) |
50 | | -% orig=octavezz(ss,info) |
| 49 | +% NO_ZMAT=1 % by setting this flag to 1 in the caller or global workspace, octavezmat won't warn zmat is missing |
| 50 | +% [ss,info]=octavezmat(ones(10)) |
| 51 | +% orig=octavezmat(ss,info) |
51 | 52 | % |
52 | 53 | % license: |
53 | 54 | % BSD or GPL version 3, see LICENSE_{BSD,GPLv3}.txt files for details |
54 | 55 | % |
55 | 56 | % -- this function is part of JSONLab toolbox (http://iso2mesh.sf.net/cgi-bin/index.cgi?jsonlab) |
56 | 57 | % |
57 | 58 |
|
| 59 | +nowarning = getvarfrom({'caller', 'base'},'NO_ZMAT'); |
| 60 | + |
| 61 | +if(isempty(nowarning) || nowarning == 0) |
| 62 | + warning('You are recommended to install ZMat (http://github.com/NeuroJSON/zmat) get much faster speed in Octave'); |
| 63 | +end |
| 64 | + |
58 | 65 | if(nargin < 1) |
59 | | - fprintf(1,'Format: output = octavezz(data, iscompress, zipmethod)\n'); |
| 66 | + fprintf(1,'Format: output = octavezmat(data, iscompress, zipmethod)\n'); |
60 | 67 | return; |
61 | 68 | end |
62 | 69 |
|
|
73 | 80 | iscompress = 0; |
74 | 81 | end |
75 | 82 |
|
| 83 | +if (~(ischar(data) || islogical(data) || (isnumeric(data) && isreal(data)))) |
| 84 | + error('input must be a char, non-complex numeric or logical vector or N-D array'); |
| 85 | +end |
| 86 | + |
| 87 | +if (ischar(data)) |
| 88 | + data = uint8(data); |
| 89 | +end |
| 90 | + |
76 | 91 | fname=tempname; |
77 | 92 | tmpfile=fname; |
78 | 93 | outputfile=fname; |
|
91 | 106 | if(~fd) |
92 | 107 | error('unable to create temporary file'); |
93 | 108 | end |
94 | | -fwrite(fd, data, 'uint8'); |
| 109 | + |
| 110 | +fwrite(fd, typecast(data(:), 'uint8'), 'uint8'); |
95 | 111 | fclose(fd); |
96 | 112 |
|
97 | 113 | if(iscompress) |
|
113 | 129 | end |
114 | 130 | end |
115 | 131 |
|
| 132 | +if(exist(tmpfile, 'file')) |
| 133 | + delete(tmpfile); |
| 134 | +end |
| 135 | + |
116 | 136 | fd=fopen(outputfile, 'rb'); |
117 | 137 | if(~fd) |
118 | 138 | error('failed to unzip buffer'); |
119 | 139 | end |
120 | | -varargout{1}=fread(fd, [1 inf], 'uint8'); |
| 140 | +varargout{1}=fread(fd, [1 inf], 'uint8=>uint8'); |
121 | 141 | fclose(fd); |
122 | 142 |
|
| 143 | + |
| 144 | +if(exist(outputfile, 'file')) |
| 145 | + delete(outputfile); |
| 146 | +end |
| 147 | + |
123 | 148 | if(nargout>1) |
124 | 149 | varargout{2}=struct('type',class(data),'size',size(data),'method',zipmethod,'status',0, 'level', iscompress); |
125 | 150 | end |
|
0 commit comments