Changeset 8 for trunk


Ignore:
Timestamp:
09/22/05 13:34:56 (19 years ago)
Author:
thauvin
Message:
  • fix test
  • fix Compressed::ls
  • compression format detected by Compressed
Location:
trunk/soft/ObsData/ObsData
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • trunk/soft/ObsData/ObsData/Archive.pm

    • Property cvs2svn:cvs-rev changed from 1.3 to 1.4
    r7 r8  
    77use File::Copy; 
    88use File::Temp qw/ tempfile /; 
     9use ObsData::Archive::Compressed; 
    910 
    1011sub new { 
     
    2021     
    2122    for ($archive) { 
    22         /\.gz$/ and do { 
     23        /\.(gz|bz2|Z)$/ and do { 
    2324            $beclass = 'Compressed'; 
    24             $options{uncomp} = 'gzip -dc'; 
    25             last; 
    26         }; 
    27         /\.bz2$/ and do { 
    28             $beclass = 'Compressed'; 
    29             $options{uncomp} = 'bzip2 -dc'; 
    3025            last; 
    3126        }; 
     
    3429    if ($beclass) { 
    3530        my $obj; 
    36         eval("require $class\:\:$beclass;"); 
     31        # eval("require $class\:\:$beclass;"); 
    3732        eval("\$obj = $class\:\:$beclass->new(\$o);"); 
    3833        return $obj; 
  • trunk/soft/ObsData/ObsData/Archive/Compressed.pm

    • Property cvs2svn:cvs-rev changed from 1.1 to 1.2
    r7 r8  
    11# $Id$ 
    22 
    3 package ObsData::Archive::Gzip; 
     3package ObsData::Archive::Compressed; 
    44 
    55use strict; 
    66use warnings; 
     7use File::Copy; 
     8use File::Temp qw/ tempfile /; 
    79 
    810our @ISA = qw(ObsData::Archive); 
    911 
    1012sub new { 
    11     my ($class, %options) = @_; 
     13    my ($class, $options) = @_; 
    1214 
    13     bless(\%options, $class); 
     15    if (!$options->{uncomp}) { 
     16        for ($options->{archive}) { 
     17            /\.(Z|gz)$/ and $options->{uncomp} = 'gzip -dc'; 
     18            /\.bz2$/ and $options->{uncomp} = 'bzip2 -dc'; 
     19        } 
     20    } 
     21     
     22    bless($options, $class); 
    1423} 
    1524 
     
    2029sub ls { 
    2130    my ($self) = @_; 
    22     my ($file) = $self->{archive} =~ m!^(?:.*/)?(.*)(?:\.gz)?!; 
    23     return $file; 
     31    $self->{archive} =~ m,^(?:.*/)?(?:(.*)(?:\.(?:gz|bz2|Z))|(.*))$,; 
     32    return $1 || $2; 
    2433} 
    2534 
     
    4150    } 
    4251 
    43     open(my $sourcefh, "gzip -dc '$self->{archive}' |") or return undef; 
     52    open(my $sourcefh, "$self->{uncomp} '$self->{archive}' |") or return undef; 
    4453     
    4554    if(!copy($sourcefh, $fh)) { 
Note: See TracChangeset for help on using the changeset viewer.