Changeset 5 for trunk


Ignore:
Timestamp:
09/21/05 13:21:13 (19 years ago)
Author:
thauvin
Message:
  • add extract
  • add test
Location:
trunk/soft/ObsData
Files:
5 added
1 edited

Legend:

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

    • Property cvs2svn:cvs-rev changed from 1.1 to 1.2
    r4 r5  
    55use strict; 
    66use warnings; 
     7use File::Copy; 
     8use File::Temp qw/ tempfile /; 
    79 
    810sub new { 
     
    2830} 
    2931 
     32sub DESTROY { 
     33    my ($self) = @_; 
     34} 
     35 
    3036sub ls { 
    3137    my ($self) = @_; 
    32     my ($file) = $self->{archive} =~ m!^(:?.*/)?(.*)!; 
     38    my ($file) = $self->{archive} =~ m!^(?:.*/)?(.*)!; 
    3339    return $file; 
     40} 
     41 
     42sub extract { 
     43    my ($self, $file, $dest) = @_; 
     44    # the devel should specify the file he want 
     45    # as the basic contains only 1 file... this does not matter 
     46 
     47    my ($fh, $fname); 
     48     
     49    if ($dest) { 
     50        $fname = $dest; 
     51        open($fh, '>', $dest) or return undef; 
     52    } else { 
     53        ($fh, $fname) = tempfile( 
     54            DIR => $self->_tempdir, 
     55            UNLINK => 1, 
     56        ) or return undef; 
     57    } 
     58     
     59    if(!copy($self->{archive}, $fh)) { 
     60        unlink($fname); 
     61        return undef; 
     62    } 
     63     
     64    close($fh); 
     65    $fname 
     66} 
     67 
     68### Private method 
     69 
     70sub _tempdir { 
     71    my ($self) = @_; 
     72    $self->{tmpdir} || $ENV{TMPDIR} 
    3473} 
    3574 
     
    4887list the content of the archive 
    4988 
     89=item extract 
     90 
     91Extract a file from the archive and return the filename of extract file 
Note: See TracChangeset for help on using the changeset viewer.