annotate scripts/miscellaneous/gzip.m @ 19243:91a6f06c5052

Overhaul gzip.m and gunzip.m These functions now operate in the directory where the archive file is located rather than the current directory. * gunzip.m: Redo docstring. Default directory for unpacking is now the directory where the .gz file resides. Eliminate unnecessary varargout usage. Eliminate unnecessary mfilename() function call by replacing with string "gunzip". Add %!assert(1) to remove file from test statistics. The tests are located in gzip.m * gzip.m: Redo docstring. Rename outdir input variable to dir to match other compress/uncompress routines. * unpack.m: Redo seealso links in docstring.
author Rik <rik@octave.org>
date Thu, 09 Oct 2014 20:38:04 -0700
parents 57d5bd8700df
children a4e993343e93
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
17744
d63878346099 maint: Update copyright notices for release.
John W. Eaton <jwe@octave.org>
parents: 17336
diff changeset
1 ## Copyright (C) 2007-2013 David Bateman
6869
f9c893831e68 [project @ 2007-09-06 16:38:44 by dbateman]
dbateman
parents:
diff changeset
2 ##
f9c893831e68 [project @ 2007-09-06 16:38:44 by dbateman]
dbateman
parents:
diff changeset
3 ## This file is part of Octave.
f9c893831e68 [project @ 2007-09-06 16:38:44 by dbateman]
dbateman
parents:
diff changeset
4 ##
f9c893831e68 [project @ 2007-09-06 16:38:44 by dbateman]
dbateman
parents:
diff changeset
5 ## Octave is free software; you can redistribute it and/or modify it
f9c893831e68 [project @ 2007-09-06 16:38:44 by dbateman]
dbateman
parents:
diff changeset
6 ## under the terms of the GNU General Public License as published by
7016
93c65f2a5668 [project @ 2007-10-12 06:40:56 by jwe]
jwe
parents: 7001
diff changeset
7 ## the Free Software Foundation; either version 3 of the License, or (at
93c65f2a5668 [project @ 2007-10-12 06:40:56 by jwe]
jwe
parents: 7001
diff changeset
8 ## your option) any later version.
6869
f9c893831e68 [project @ 2007-09-06 16:38:44 by dbateman]
dbateman
parents:
diff changeset
9 ##
f9c893831e68 [project @ 2007-09-06 16:38:44 by dbateman]
dbateman
parents:
diff changeset
10 ## Octave is distributed in the hope that it will be useful, but
f9c893831e68 [project @ 2007-09-06 16:38:44 by dbateman]
dbateman
parents:
diff changeset
11 ## WITHOUT ANY WARRANTY; without even the implied warranty of
f9c893831e68 [project @ 2007-09-06 16:38:44 by dbateman]
dbateman
parents:
diff changeset
12 ## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
f9c893831e68 [project @ 2007-09-06 16:38:44 by dbateman]
dbateman
parents:
diff changeset
13 ## General Public License for more details.
f9c893831e68 [project @ 2007-09-06 16:38:44 by dbateman]
dbateman
parents:
diff changeset
14 ##
f9c893831e68 [project @ 2007-09-06 16:38:44 by dbateman]
dbateman
parents:
diff changeset
15 ## You should have received a copy of the GNU General Public License
7016
93c65f2a5668 [project @ 2007-10-12 06:40:56 by jwe]
jwe
parents: 7001
diff changeset
16 ## along with Octave; see the file COPYING. If not, see
93c65f2a5668 [project @ 2007-10-12 06:40:56 by jwe]
jwe
parents: 7001
diff changeset
17 ## <http://www.gnu.org/licenses/>.
6869
f9c893831e68 [project @ 2007-09-06 16:38:44 by dbateman]
dbateman
parents:
diff changeset
18
f9c893831e68 [project @ 2007-09-06 16:38:44 by dbateman]
dbateman
parents:
diff changeset
19 ## -*- texinfo -*-
19243
91a6f06c5052 Overhaul gzip.m and gunzip.m
Rik <rik@octave.org>
parents: 18301
diff changeset
20 ## @deftypefn {Function File} {@var{filelist} =} gzip (@var{files})
91a6f06c5052 Overhaul gzip.m and gunzip.m
Rik <rik@octave.org>
parents: 18301
diff changeset
21 ## @deftypefnx {Function File} {@var{filelist} =} gzip (@var{files}, @var{dir})
91a6f06c5052 Overhaul gzip.m and gunzip.m
Rik <rik@octave.org>
parents: 18301
diff changeset
22 ## Compress the list of files and directories specified in @var{files}.
91a6f06c5052 Overhaul gzip.m and gunzip.m
Rik <rik@octave.org>
parents: 18301
diff changeset
23 ##
91a6f06c5052 Overhaul gzip.m and gunzip.m
Rik <rik@octave.org>
parents: 18301
diff changeset
24 ## @var{files} is a character array or cell array of strings. Each file is
91a6f06c5052 Overhaul gzip.m and gunzip.m
Rik <rik@octave.org>
parents: 18301
diff changeset
25 ## compressed separately and a new file with a @file{".gz"} extension is
91a6f06c5052 Overhaul gzip.m and gunzip.m
Rik <rik@octave.org>
parents: 18301
diff changeset
26 ## created. The original files are not modified, but, existing compressed
91a6f06c5052 Overhaul gzip.m and gunzip.m
Rik <rik@octave.org>
parents: 18301
diff changeset
27 ## files will be silently overwritten. If a directory is specified then
91a6f06c5052 Overhaul gzip.m and gunzip.m
Rik <rik@octave.org>
parents: 18301
diff changeset
28 ## @code{gzip} recursively compresses all files in the directory.
91a6f06c5052 Overhaul gzip.m and gunzip.m
Rik <rik@octave.org>
parents: 18301
diff changeset
29 ##
91a6f06c5052 Overhaul gzip.m and gunzip.m
Rik <rik@octave.org>
parents: 18301
diff changeset
30 ## If @var{dir} is defined the compressed files are placed in this directory.
91a6f06c5052 Overhaul gzip.m and gunzip.m
Rik <rik@octave.org>
parents: 18301
diff changeset
31 ##
91a6f06c5052 Overhaul gzip.m and gunzip.m
Rik <rik@octave.org>
parents: 18301
diff changeset
32 ## The optional output @var{filelist} is a list of the compressed files.
91a6f06c5052 Overhaul gzip.m and gunzip.m
Rik <rik@octave.org>
parents: 18301
diff changeset
33 ## @seealso{gunzip, bzip2, zip, tar, unpack}
6869
f9c893831e68 [project @ 2007-09-06 16:38:44 by dbateman]
dbateman
parents:
diff changeset
34 ## @end deftypefn
f9c893831e68 [project @ 2007-09-06 16:38:44 by dbateman]
dbateman
parents:
diff changeset
35
19243
91a6f06c5052 Overhaul gzip.m and gunzip.m
Rik <rik@octave.org>
parents: 18301
diff changeset
36 function filelist = gzip (varargin)
91a6f06c5052 Overhaul gzip.m and gunzip.m
Rik <rik@octave.org>
parents: 18301
diff changeset
37
91a6f06c5052 Overhaul gzip.m and gunzip.m
Rik <rik@octave.org>
parents: 18301
diff changeset
38 if (nargin < 1 || nargin > 2 || nargout > 1)
6869
f9c893831e68 [project @ 2007-09-06 16:38:44 by dbateman]
dbateman
parents:
diff changeset
39 print_usage ();
f9c893831e68 [project @ 2007-09-06 16:38:44 by dbateman]
dbateman
parents:
diff changeset
40 endif
13141
e81ddf9cacd5 maint: untabify and remove trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents: 12500
diff changeset
41
12499
a3019189ac51 Improve file archiving functions (gzip, bzip2, zip, unpack)
Rik <octave@nomad.inbox5.com>
parents: 11587
diff changeset
42 if (nargout == 0)
a3019189ac51 Improve file archiving functions (gzip, bzip2, zip, unpack)
Rik <octave@nomad.inbox5.com>
parents: 11587
diff changeset
43 __xzip__ ("gzip", "gz", "gzip -r %s", varargin{:});
a3019189ac51 Improve file archiving functions (gzip, bzip2, zip, unpack)
Rik <octave@nomad.inbox5.com>
parents: 11587
diff changeset
44 else
19243
91a6f06c5052 Overhaul gzip.m and gunzip.m
Rik <rik@octave.org>
parents: 18301
diff changeset
45 filelist = __xzip__ ("gzip", "gz", "gzip -r %s", varargin{:});
12499
a3019189ac51 Improve file archiving functions (gzip, bzip2, zip, unpack)
Rik <octave@nomad.inbox5.com>
parents: 11587
diff changeset
46 endif
a3019189ac51 Improve file archiving functions (gzip, bzip2, zip, unpack)
Rik <octave@nomad.inbox5.com>
parents: 11587
diff changeset
47
6869
f9c893831e68 [project @ 2007-09-06 16:38:44 by dbateman]
dbateman
parents:
diff changeset
48 endfunction
f9c893831e68 [project @ 2007-09-06 16:38:44 by dbateman]
dbateman
parents:
diff changeset
49
14363
f3d52523cde1 Use Octave coding conventions in all m-file %!test blocks
Rik <octave@nomad.inbox5.com>
parents: 14359
diff changeset
50
8349
02beb5be5683 add bzip2 function
Thorsten Meyer <thorsten.meyier@gmx.de>
parents: 7017
diff changeset
51 %!xtest
17336
b81b9d079515 Use '##' for comments which stand alone on a line.
Rik <rik@octave.org>
parents: 17281
diff changeset
52 %! ## test gzip together with gunzip
14363
f3d52523cde1 Use Octave coding conventions in all m-file %!test blocks
Rik <octave@nomad.inbox5.com>
parents: 14359
diff changeset
53 %! unwind_protect
19243
91a6f06c5052 Overhaul gzip.m and gunzip.m
Rik <rik@octave.org>
parents: 18301
diff changeset
54 %! filename = tempname;
91a6f06c5052 Overhaul gzip.m and gunzip.m
Rik <rik@octave.org>
parents: 18301
diff changeset
55 %! dummy = pi;
14363
f3d52523cde1 Use Octave coding conventions in all m-file %!test blocks
Rik <octave@nomad.inbox5.com>
parents: 14359
diff changeset
56 %! save (filename, "dummy");
19243
91a6f06c5052 Overhaul gzip.m and gunzip.m
Rik <rik@octave.org>
parents: 18301
diff changeset
57 %! dirname = tempname;
14363
f3d52523cde1 Use Octave coding conventions in all m-file %!test blocks
Rik <octave@nomad.inbox5.com>
parents: 14359
diff changeset
58 %! mkdir (dirname);
19243
91a6f06c5052 Overhaul gzip.m and gunzip.m
Rik <rik@octave.org>
parents: 18301
diff changeset
59 %! filelist = gzip (filename, dirname);
91a6f06c5052 Overhaul gzip.m and gunzip.m
Rik <rik@octave.org>
parents: 18301
diff changeset
60 %! filelist = filelist{1};
91a6f06c5052 Overhaul gzip.m and gunzip.m
Rik <rik@octave.org>
parents: 18301
diff changeset
61 %! [~, basename, extension] = fileparts (filename);
91a6f06c5052 Overhaul gzip.m and gunzip.m
Rik <rik@octave.org>
parents: 18301
diff changeset
62 %! if (! strcmp (filelist, [dirname, filesep, basename, extension, ".gz"]))
14363
f3d52523cde1 Use Octave coding conventions in all m-file %!test blocks
Rik <octave@nomad.inbox5.com>
parents: 14359
diff changeset
63 %! error ("gzipped file does not match expected name!");
f3d52523cde1 Use Octave coding conventions in all m-file %!test blocks
Rik <octave@nomad.inbox5.com>
parents: 14359
diff changeset
64 %! endif
19243
91a6f06c5052 Overhaul gzip.m and gunzip.m
Rik <rik@octave.org>
parents: 18301
diff changeset
65 %! if (! exist (filelist, "file"))
14363
f3d52523cde1 Use Octave coding conventions in all m-file %!test blocks
Rik <octave@nomad.inbox5.com>
parents: 14359
diff changeset
66 %! error ("gzipped file cannot be found!");
f3d52523cde1 Use Octave coding conventions in all m-file %!test blocks
Rik <octave@nomad.inbox5.com>
parents: 14359
diff changeset
67 %! endif
19243
91a6f06c5052 Overhaul gzip.m and gunzip.m
Rik <rik@octave.org>
parents: 18301
diff changeset
68 %! gunzip (filelist);
18301
57d5bd8700df gzip.m: Re-write %!test not to depend on external system diff command.
Rik <rik@octave.org>
parents: 17744
diff changeset
69 %! fid = fopen (filename, "rb");
57d5bd8700df gzip.m: Re-write %!test not to depend on external system diff command.
Rik <rik@octave.org>
parents: 17744
diff changeset
70 %! assert (fid >= 0);
57d5bd8700df gzip.m: Re-write %!test not to depend on external system diff command.
Rik <rik@octave.org>
parents: 17744
diff changeset
71 %! orig_data = fread (fid);
57d5bd8700df gzip.m: Re-write %!test not to depend on external system diff command.
Rik <rik@octave.org>
parents: 17744
diff changeset
72 %! fclose (fid);
57d5bd8700df gzip.m: Re-write %!test not to depend on external system diff command.
Rik <rik@octave.org>
parents: 17744
diff changeset
73 %! fid = fopen ([dirname filesep basename extension], "rb");
57d5bd8700df gzip.m: Re-write %!test not to depend on external system diff command.
Rik <rik@octave.org>
parents: 17744
diff changeset
74 %! assert (fid >= 0);
57d5bd8700df gzip.m: Re-write %!test not to depend on external system diff command.
Rik <rik@octave.org>
parents: 17744
diff changeset
75 %! new_data = fread (fid);
57d5bd8700df gzip.m: Re-write %!test not to depend on external system diff command.
Rik <rik@octave.org>
parents: 17744
diff changeset
76 %! fclose (fid);
57d5bd8700df gzip.m: Re-write %!test not to depend on external system diff command.
Rik <rik@octave.org>
parents: 17744
diff changeset
77 %! if (orig_data != new_data)
19243
91a6f06c5052 Overhaul gzip.m and gunzip.m
Rik <rik@octave.org>
parents: 18301
diff changeset
78 %! error ("gunzipped file not equal to original file!");
18301
57d5bd8700df gzip.m: Re-write %!test not to depend on external system diff command.
Rik <rik@octave.org>
parents: 17744
diff changeset
79 %! endif
14363
f3d52523cde1 Use Octave coding conventions in all m-file %!test blocks
Rik <octave@nomad.inbox5.com>
parents: 14359
diff changeset
80 %! unwind_protect_cleanup
f3d52523cde1 Use Octave coding conventions in all m-file %!test blocks
Rik <octave@nomad.inbox5.com>
parents: 14359
diff changeset
81 %! delete (filename);
f3d52523cde1 Use Octave coding conventions in all m-file %!test blocks
Rik <octave@nomad.inbox5.com>
parents: 14359
diff changeset
82 %! delete ([dirname, filesep, basename, extension]);
f3d52523cde1 Use Octave coding conventions in all m-file %!test blocks
Rik <octave@nomad.inbox5.com>
parents: 14359
diff changeset
83 %! rmdir (dirname);
f3d52523cde1 Use Octave coding conventions in all m-file %!test blocks
Rik <octave@nomad.inbox5.com>
parents: 14359
diff changeset
84 %! end_unwind_protect
f3d52523cde1 Use Octave coding conventions in all m-file %!test blocks
Rik <octave@nomad.inbox5.com>
parents: 14359
diff changeset
85
f3d52523cde1 Use Octave coding conventions in all m-file %!test blocks
Rik <octave@nomad.inbox5.com>
parents: 14359
diff changeset
86 %!error gzip ()
f3d52523cde1 Use Octave coding conventions in all m-file %!test blocks
Rik <octave@nomad.inbox5.com>
parents: 14359
diff changeset
87 %!error gzip ("1", "2", "3")
19243
91a6f06c5052 Overhaul gzip.m and gunzip.m
Rik <rik@octave.org>
parents: 18301
diff changeset
88 %!error <output directory does not exist> gzip ("1", tempname)
14363
f3d52523cde1 Use Octave coding conventions in all m-file %!test blocks
Rik <octave@nomad.inbox5.com>
parents: 14359
diff changeset
89 %!error <FILES must be a character array or cellstr> gzip (1)
f3d52523cde1 Use Octave coding conventions in all m-file %!test blocks
Rik <octave@nomad.inbox5.com>
parents: 14359
diff changeset
90