File: Zip.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 (44 lines) | stat: -rw-r--r-- 941 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
40
41
42
43
44
package Archive::Any::Create::Zip;
use strict;

use Archive::Zip qw(:ERROR_CODES);

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

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

sub add_file {
    my $self = shift;
    my($file, $data) = @_;
    $file = "$self->{container}/$file" if $self->{container};
    $self->{zip}->addString($data, $file);
}

sub write_file {
    my $self = shift;
    my($file) = @_;
    my $err = $self->{zip}->writeToFileNamed($file);
    $err == AZ_OK
        or throw Archive::Any::Create::Error(error => "write_file failed ($err)");
    1;
}

sub write_filehandle {
    my $self = shift;
    my($fh)  = @_;
    my $err = $self->{zip}->writeToFileHandle($fh);
    $err == AZ_OK
        or throw Archive::Any::Create::Error(error => "write_filehandle failed ($err)");
    1;
}

1;