Mercurial > octave-antonio
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 |
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 | 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 | |
7016 | 7 ## the Free Software Foundation; either version 3 of the License, or (at |
8 ## your option) any later version. | |
6869 | 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 | |
7016 | 16 ## along with Octave; see the file COPYING. If not, see |
17 ## <http://www.gnu.org/licenses/>. | |
6869 | 18 |
19 ## -*- texinfo -*- | |
19243 | 20 ## @deftypefn {Function File} {@var{filelist} =} gzip (@var{files}) |
21 ## @deftypefnx {Function File} {@var{filelist} =} gzip (@var{files}, @var{dir}) | |
22 ## Compress the list of files and directories specified in @var{files}. | |
23 ## | |
24 ## @var{files} is a character array or cell array of strings. Each file is | |
25 ## compressed separately and a new file with a @file{".gz"} extension is | |
26 ## created. The original files are not modified, but, existing compressed | |
27 ## files will be silently overwritten. If a directory is specified then | |
28 ## @code{gzip} recursively compresses all files in the directory. | |
29 ## | |
30 ## If @var{dir} is defined the compressed files are placed in this directory. | |
31 ## | |
32 ## The optional output @var{filelist} is a list of the compressed files. | |
33 ## @seealso{gunzip, bzip2, zip, tar, unpack} | |
6869 | 34 ## @end deftypefn |
35 | |
19243 | 36 function filelist = gzip (varargin) |
37 | |
38 if (nargin < 1 || nargin > 2 || nargout > 1) | |
6869 | 39 print_usage (); |
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 | 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 | 48 endfunction |
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 | 54 %! filename = tempname; |
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 | 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 | 59 %! filelist = gzip (filename, dirname); |
60 %! filelist = filelist{1}; | |
61 %! [~, basename, extension] = fileparts (filename); | |
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 | 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 | 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 | 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 | 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 |