1 ## Copyright (C) 2007-2012 David Bateman
3 ## This file is part of Octave.
5 ## Octave is free software; you can redistribute it and/or modify it
6 ## under the terms of the GNU General Public License as published by
7 ## the Free Software Foundation; either version 3 of the License, or (at
8 ## your option) any later version.
10 ## Octave is distributed in the hope that it will be useful, but
11 ## WITHOUT ANY WARRANTY; without even the implied warranty of
12 ## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 ## General Public License for more details.
15 ## You should have received a copy of the GNU General Public License
16 ## along with Octave; see the file COPYING. If not, see
17 ## <http://www.gnu.org/licenses/>.
20 ## @deftypefn {Function File} {@var{entries} =} gzip (@var{files})
21 ## @deftypefnx {Function File} {@var{entries} =} gzip (@var{files}, @var{outdir})
22 ## Compress the list of files and/or directories specified in @var{files}.
23 ## Each file is compressed separately and a new file with a '.gz' extension
24 ## is created. The original files are not modified. Existing compressed
25 ## files are silently overwritten. If @var{outdir} is defined the compressed
26 ## files are placed in this directory.
27 ## @seealso{gunzip, bzip2, zip, tar}
30 function entries = gzip (varargin)
31 if (nargin != 1 && nargin != 2) || (nargout > 1)
36 __xzip__ ("gzip", "gz", "gzip -r %s", varargin{:});
38 entries = __xzip__ ("gzip", "gz", "gzip -r %s", varargin{:});
43 %!error <Invalid call to gzip. Correct usage is> gzip("1", "2", "3");
44 %!error <Invalid call to gzip. Correct usage is> gzip();
45 %!error <output directory does not exist> gzip("1", tmpnam);
46 %!error <FILES must be a character array or cellstr> gzip(1);
48 %! # test gzip together with gunzip
52 %! save(filename, "dummy");
55 %! entry = gzip(filename, dirname);
56 %! [path, basename, extension] = fileparts(filename);
57 %! if ! strcmp(entry, [dirname, filesep, basename, extension, ".gz"])
58 %! error("gzipped file does not match expected name!");
60 %! if ! exist(entry, "file")
61 %! error("gzipped file cannot be found!");
64 %! if (system(sprintf("diff %s %s%c%s%s", filename, dirname, filesep,
65 %! basename, extension)))
66 %! error("unzipped file not equal to original file!");
68 %! unwind_protect_cleanup
70 %! delete([dirname, filesep, basename, extension]);