line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
# Copyright (c) 2009, 2010 Oleksandr Tymoshenko |
2
|
|
|
|
|
|
|
# All rights reserved. |
3
|
|
|
|
|
|
|
|
4
|
|
|
|
|
|
|
# Redistribution and use in source and binary forms, with or without |
5
|
|
|
|
|
|
|
# modification, are permitted provided that the following conditions |
6
|
|
|
|
|
|
|
# are met: |
7
|
|
|
|
|
|
|
# 1. Redistributions of source code must retain the above copyright |
8
|
|
|
|
|
|
|
# notice, this list of conditions and the following disclaimer. |
9
|
|
|
|
|
|
|
# 2. Redistributions in binary form must reproduce the above copyright |
10
|
|
|
|
|
|
|
# notice, this list of conditions and the following disclaimer in the |
11
|
|
|
|
|
|
|
# documentation and/or other materials provided with the distribution. |
12
|
|
|
|
|
|
|
|
13
|
|
|
|
|
|
|
# THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND |
14
|
|
|
|
|
|
|
# ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE |
15
|
|
|
|
|
|
|
# IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE |
16
|
|
|
|
|
|
|
# ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE |
17
|
|
|
|
|
|
|
# FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL |
18
|
|
|
|
|
|
|
# DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS |
19
|
|
|
|
|
|
|
# OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) |
20
|
|
|
|
|
|
|
# HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT |
21
|
|
|
|
|
|
|
# LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY |
22
|
|
|
|
|
|
|
# OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF |
23
|
|
|
|
|
|
|
# SUCH DAMAGE. |
24
|
|
|
|
|
|
|
|
25
|
|
|
|
|
|
|
package EBook::EPUB::Lite::Container::Zip; |
26
|
|
|
|
|
|
|
|
27
|
4
|
|
|
4
|
|
18
|
use strict; |
|
4
|
|
|
|
|
6
|
|
|
4
|
|
|
|
|
141
|
|
28
|
4
|
|
|
4
|
|
19
|
use warnings; |
|
4
|
|
|
|
|
6
|
|
|
4
|
|
|
|
|
129
|
|
29
|
4
|
|
|
4
|
|
1779
|
use EBook::EPUB::Lite::Container; |
|
4
|
|
|
|
|
49
|
|
|
4
|
|
|
|
|
153
|
|
30
|
4
|
|
|
4
|
|
2190
|
use Archive::Zip qw( :ERROR_CODES :CONSTANTS );; |
|
4
|
|
|
|
|
185403
|
|
|
4
|
|
|
|
|
680
|
|
31
|
4
|
|
|
4
|
|
30
|
use File::Temp qw/tempfile/; |
|
4
|
|
|
|
|
6
|
|
|
4
|
|
|
|
|
254
|
|
32
|
4
|
|
|
4
|
|
18
|
use Carp; |
|
4
|
|
|
|
|
6
|
|
|
4
|
|
|
|
|
196
|
|
33
|
|
|
|
|
|
|
|
34
|
4
|
|
|
4
|
|
16
|
use vars qw(@ISA); |
|
4
|
|
|
|
|
6
|
|
|
4
|
|
|
|
|
1156
|
|
35
|
|
|
|
|
|
|
@ISA = qw(EBook::EPUB::Lite::Container); |
36
|
|
|
|
|
|
|
|
37
|
|
|
|
|
|
|
sub new |
38
|
|
|
|
|
|
|
{ |
39
|
2
|
|
|
2
|
1
|
4
|
my ($class, $zipfile) = @_; |
40
|
2
|
|
|
|
|
22
|
my $self = $class->SUPER::new(); |
41
|
2
|
|
|
|
|
14
|
$self->{zipfile} = $zipfile; |
42
|
|
|
|
|
|
|
|
43
|
2
|
|
|
|
|
4
|
return $self; |
44
|
|
|
|
|
|
|
} |
45
|
|
|
|
|
|
|
|
46
|
|
|
|
|
|
|
sub write |
47
|
|
|
|
|
|
|
{ |
48
|
2
|
|
|
2
|
1
|
3
|
my ($self) = @_; |
49
|
2
|
|
|
|
|
19
|
my $zip = Archive::Zip->new(); |
50
|
|
|
|
|
|
|
|
51
|
|
|
|
|
|
|
# mimetype should come first |
52
|
2
|
|
|
|
|
76
|
$zip->addString("application/epub+zip", "mimetype"); |
53
|
|
|
|
|
|
|
|
54
|
2
|
|
|
|
|
577
|
foreach my $f (@{$self->{files}}) { |
|
2
|
|
|
|
|
9
|
|
55
|
|
|
|
|
|
|
$zip->addFileOrDirectory($f->{frompath}, |
56
|
15
|
|
|
|
|
3458
|
$f->{containerpath}); |
57
|
|
|
|
|
|
|
} |
58
|
|
|
|
|
|
|
|
59
|
2
|
|
|
|
|
455
|
my (undef, $tmp_container) = tempfile; |
60
|
2
|
50
|
|
|
|
842
|
if (!defined($self->write_container($tmp_container))) { |
61
|
0
|
|
|
|
|
0
|
carp "Failed to write container to temporary file $tmp_container"; |
62
|
0
|
|
|
|
|
0
|
unlink($tmp_container); |
63
|
0
|
|
|
|
|
0
|
return; |
64
|
|
|
|
|
|
|
} |
65
|
|
|
|
|
|
|
|
66
|
2
|
|
|
|
|
10
|
$zip->addFile($tmp_container, "META-INF/container.xml"); |
67
|
|
|
|
|
|
|
|
68
|
2
|
|
|
|
|
404
|
my (undef, $tmp_encryption) = tempfile; |
69
|
2
|
100
|
|
|
|
569
|
if ($self->has_encrypted_files) { |
70
|
1
|
50
|
|
|
|
8
|
if (!defined($self->write_encryption($tmp_encryption))) { |
71
|
0
|
|
|
|
|
0
|
carp "Failed to write encryption to temporary file $tmp_encryption"; |
72
|
0
|
|
|
|
|
0
|
unlink($tmp_encryption); |
73
|
0
|
|
|
|
|
0
|
unlink($tmp_container); |
74
|
0
|
|
|
|
|
0
|
return; |
75
|
|
|
|
|
|
|
} |
76
|
|
|
|
|
|
|
|
77
|
1
|
|
|
|
|
8
|
$zip->addFile($tmp_encryption, "META-INF/encryption.xml"); |
78
|
|
|
|
|
|
|
} |
79
|
|
|
|
|
|
|
|
80
|
2
|
|
|
|
|
260
|
my $result = $zip->writeToFileNamed($self->{zipfile}); |
81
|
2
|
|
|
|
|
33638
|
unlink($tmp_encryption); |
82
|
2
|
|
|
|
|
89
|
unlink($tmp_container); |
83
|
2
|
50
|
|
|
|
142
|
return 1 if ($result == AZ_OK); |
84
|
|
|
|
|
|
|
# We failed |
85
|
0
|
|
|
|
|
|
return; |
86
|
|
|
|
|
|
|
} |
87
|
|
|
|
|
|
|
|
88
|
|
|
|
|
|
|
__END__ |