[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
decompress any compressed type
From: |
Bill Denney |
Subject: |
decompress any compressed type |
Date: |
Tue, 17 Oct 2006 00:46:36 -0400 |
User-agent: |
Thunderbird 1.5.0.7 (Windows/20060909) |
There have been several requests recently to have the package manager
handle arbitrary compressed types. While I've not implemented all of
the features required for this in the associated functions, here is
decompress.m that takes the same arguments as any of the other
decompression routines, but it will just choose the right one based on
file extension.
Eventually, we may want to move all the decompression code to within
this function and have the others just call it (so that everything
correctly does unwind_protect, changing directories, etc. without having
essentially duplicated code). John, if you'd like that, I can probably
work on it tomorrow.
I chose the name decompress instead of uncompress because uncompress is
the unix command that specifically expands .Z files.
Bill
scripts/ChangeLog:
2006-10-17 Bill Denney <address@hidden>
* miscellaneous/decompress.m: new function, decompress any file
based on its extension
## Copyright (C) 2005 Bill Denney
##
## This file is part of Octave.
##
## Octave is free software; you can redistribute it and/or modify it
## under the terms of the GNU General Public License as published by
## the Free Software Foundation; either version 2, or (at your option)
## any later version.
##
## Octave is distributed in the hope that it will be useful, but
## WITHOUT ANY WARRANTY; without even the implied warranty of
## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
## General Public License for more details.
##
## You should have received a copy of the GNU General Public License
## along with Octave; see the file COPYING. If not, write to the Free
## Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
## 02110-1301, USA.
## -*- texinfo -*-
## @deftypefn {Function File} decompress (@var{file}, @var{dir})
## Unpack the archive @var{file} based on its extension to the directory
## @var{dir}. If @var{file} is a cellstr, then all files will be
## handled individually. If @var{dir} is not specified, it defaults to
## the current directory.
## @seealso{tar, untar, gzip, gunzip, zip, unzip}
## @end deftypefn
## Author: Bill Denney <address@hidden>
function files = decompress (file, directory)
if (nargin == 1 || nargin == 2)
if (nargin == 1)
directory = ".";
endif
if ischar (file)
[pathstr, name, ext] = fullfile (file);
## check to see if it's .tar.gz, .tar.Z, or .tar.bz2
if strcmp (ext, ".gz") || strcmp (ext, ".Z") || strcmp (ext, ".bz2")
[tmppathstr, tmpname, tmpext] = fullfile (name);
if strcmp(tmpext, ".tar")
name = tmpname;
ext = [tmpext ext];
endif
endif
elseif iscellstr (file)
files = {};
for i = 1:numel (file)
tmpfiles = decompress (file{i}, directory);
files = {files{:} tmpfiles{:}};
endfor
else
error ("decompress: invalid input file class, %s", class(file));
endif
switch lower(ext)
case {".gz" ".Z"}
files = gunzip (file, directory);
case {".tar" ".tar.gz" ".tgz" ".tar.Z"}
files = untar (file, directory);
case {".zip"}
files = unzip (file, directory);
## case {".bz2"}
## files = bunzip2 (file, directory);
otherwise
error ("decompress: unrecognised file type, %s", ext);
endswitch
else
print_usage ();
endif
endfunction
- decompress any compressed type,
Bill Denney <=