]> Creatis software - CreaPhase.git/blob - octave_packages/m/miscellaneous/gzip.m
update packages
[CreaPhase.git] / octave_packages / m / miscellaneous / gzip.m
1 ## Copyright (C) 2007-2012 David Bateman
2 ##
3 ## This file is part of Octave.
4 ##
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.
9 ##
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.
14 ##
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/>.
18
19 ## -*- texinfo -*-
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}
28 ## @end deftypefn
29
30 function entries = gzip (varargin)
31   if (nargin != 1 && nargin != 2) || (nargout > 1)
32     print_usage ();
33   endif
34
35   if (nargout == 0)
36     __xzip__ ("gzip", "gz", "gzip -r %s", varargin{:});
37   else
38     entries = __xzip__ ("gzip", "gz", "gzip -r %s", varargin{:});
39   endif
40
41 endfunction
42
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);
47 %!xtest
48 %!  # test gzip together with gunzip
49 %!  unwind_protect
50 %!    filename = tmpnam;
51 %!    dummy    = 1;
52 %!    save(filename, "dummy");
53 %!    dirname  = tmpnam;
54 %!    mkdir(dirname);
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!");
59 %!    endif
60 %!    if ! exist(entry, "file")
61 %!      error("gzipped file cannot be found!");
62 %!    endif
63 %!    gunzip(entry);
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!");
67 %!    end
68 %!  unwind_protect_cleanup
69 %!    delete(filename);
70 %!    delete([dirname, filesep, basename, extension]);
71 %!    rmdir(dirname);
72 %!  end_unwind_protect