File: Tar.pm

package info (click to toggle)
libarchive-any-create-perl 0.3-3
  • links: PTS, VCS
  • area: main
  • in suites: bookworm, forky, sid, trixie
  • size: 124 kB
  • sloc: perl: 126; makefile: 2
file content (39 lines) | stat: -rw-r--r-- 767 bytes parent folder | download | duplicates (3)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
package Archive::Any::Create::Tar;
use strict;

use Archive::Tar;

sub init {
    my $self = shift;
    my($opt) = @_;
    $self->{tar}  = Archive::Tar->new;
    $self->{comp} = $opt->{comp};
}

sub container {
    my $self = shift;
    my($dir) = @_;
    $self->{container} = $dir;
}

sub add_file {
    my $self = shift;
    my($file, $data) = @_;
    $self->{tar}->add_data($file, $data);
}

sub write_file {
    my $self = shift;
    return $self->write_filehandle(@_); # Accepts files or handles
}

sub write_filehandle {
    my $self = shift;
    my($fh)  = @_;
    my $comp = $self->{comp} ? COMPRESS_GZIP : undef;
    $self->{tar}->write($fh, $comp, $self->{container})
        or throw Archive::Any::Create::Error(error => $self->{tar}->error);
    1;
}

1;