1 ## Copyright (C) 2008-2012 Thorsten Meyer
2 ## (based on gzip.m by David Bateman)
4 ## This file is part of Octave.
6 ## Octave is free software; you can redistribute it and/or modify it
7 ## under the terms of the GNU General Public License as published by
8 ## the Free Software Foundation; either version 3 of the License, or (at
9 ## your option) any later version.
11 ## Octave is distributed in the hope that it will be useful, but
12 ## WITHOUT ANY WARRANTY; without even the implied warranty of
13 ## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 ## General Public License for more details.
16 ## You should have received a copy of the GNU General Public License
17 ## along with Octave; see the file COPYING. If not, see
18 ## <http://www.gnu.org/licenses/>.
21 ## @deftypefn {Function File} {@var{entries} =} bzip2 (@var{files})
22 ## @deftypefnx {Function File} {@var{entries} =} bzip2 (@var{files}, @var{outdir})
23 ## Compress the list of files specified in @var{files}.
24 ## Each file is compressed separately and a new file with a '.bz2' extension
25 ## is created. The original files are not modified. Existing compressed files
26 ## are silently overwritten. If @var{outdir} is defined the compressed
27 ## files are placed in this directory.
28 ## @seealso{bunzip2, gzip, zip, tar}
31 function entries = bzip2 (varargin)
33 if (nargin == 1 || nargin == 2)
35 __xzip__ ("bzip2", "bz2", "bzip2 %s", varargin{:});
37 entries = __xzip__ ("bzip2", "bz2", "bzip2 %s", varargin{:});
46 %! # test for correct cleanup of temporary files
50 %! save(filename, "dummy");
51 %! n_tmpfiles_before = length(find(strncmp("oct-", cellstr(ls(P_tmpdir)), 4)));
52 %! entry = bzip2(filename);
53 %! n_tmpfiles_after = length(find(strncmp("oct-", cellstr(ls(P_tmpdir)), 4)));
54 %! if (n_tmpfiles_before != n_tmpfiles_after)
55 %! error("bzip2 has not cleaned up temporary files correctly!");
57 %! unwind_protect_cleanup
59 %! [path, basename, extension] = fileparts(filename);
60 %! delete([basename, extension, ".bz2"]);