line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package Compress::LZMA::External; |
2
|
1
|
|
|
1
|
|
19655
|
use strict; |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
32
|
|
3
|
1
|
|
|
1
|
|
5
|
use warnings; |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
26
|
|
4
|
1
|
|
|
1
|
|
760
|
use File::Spec::Functions; |
|
1
|
|
|
|
|
1004
|
|
|
1
|
|
|
|
|
109
|
|
5
|
1
|
|
|
1
|
|
1403
|
use File::Temp qw(tempfile); |
|
1
|
|
|
|
|
30461
|
|
|
1
|
|
|
|
|
73
|
|
6
|
1
|
|
|
1
|
|
823
|
use IO::File; |
|
1
|
|
|
|
|
1349
|
|
|
1
|
|
|
|
|
535
|
|
7
|
|
|
|
|
|
|
our @ISA = qw(Exporter); |
8
|
|
|
|
|
|
|
our @EXPORT_OK = qw(compress_fast compress compress_best decompress); |
9
|
|
|
|
|
|
|
our $VERSION = '0.37'; |
10
|
|
|
|
|
|
|
|
11
|
|
|
|
|
|
|
sub compress_fast ($) { |
12
|
1
|
|
|
1
|
0
|
17
|
my $data = shift; |
13
|
1
|
|
|
|
|
6
|
return _call( $data, 'data.txt', 'lzma -c --fast -f' ); |
14
|
|
|
|
|
|
|
} |
15
|
|
|
|
|
|
|
|
16
|
|
|
|
|
|
|
sub compress ($) { |
17
|
1
|
|
|
1
|
0
|
2684
|
my $data = shift; |
18
|
1
|
|
|
|
|
27
|
return _call( $data, 'data.txt', 'lzma -c -f' ); |
19
|
|
|
|
|
|
|
} |
20
|
|
|
|
|
|
|
|
21
|
|
|
|
|
|
|
sub compress_best ($) { |
22
|
1
|
|
|
1
|
0
|
11213
|
my $data = shift; |
23
|
1
|
|
|
|
|
18
|
return _call( $data, 'data.txt', 'lzma -c --best -f' ); |
24
|
|
|
|
|
|
|
} |
25
|
|
|
|
|
|
|
|
26
|
|
|
|
|
|
|
sub decompress ($) { |
27
|
3
|
|
|
3
|
0
|
80072
|
my $data = shift; |
28
|
3
|
|
|
|
|
28
|
return _call( $data, 'data.txt.lzma', 'lzma -c -d -f' ); |
29
|
|
|
|
|
|
|
} |
30
|
|
|
|
|
|
|
|
31
|
|
|
|
|
|
|
sub _call { |
32
|
6
|
|
|
6
|
|
40
|
my ( $in, $filename, $command ) = @_; |
33
|
6
|
|
|
|
|
166
|
my $dir = File::Temp->newdir(); |
34
|
6
|
|
|
|
|
12892
|
my $path = catfile( $dir, $filename ); |
35
|
6
|
|
50
|
|
|
956
|
my $fh = IO::File->new("> $path") || die "Error opening $path: $!"; |
36
|
6
|
50
|
|
|
|
1351
|
$fh->print($in) || die "Error writing to $path: $!"; |
37
|
6
|
50
|
|
|
|
295
|
$fh->close || die "Error closing $path: $!"; |
38
|
6
|
|
50
|
|
|
703
|
$fh = IO::File->new("$command $path |") || die "Error opening lzma: $!"; |
39
|
6
|
|
|
|
|
45587
|
my $out; |
40
|
|
|
|
|
|
|
|
41
|
6
|
|
|
|
|
382
|
while ( !$fh->eof ) { |
42
|
6
|
|
|
|
|
145884
|
$out .= <$fh>; |
43
|
|
|
|
|
|
|
} |
44
|
6
|
|
|
|
|
203
|
unlink($filename); |
45
|
6
|
|
|
|
|
11185
|
return $out; |
46
|
|
|
|
|
|
|
} |
47
|
|
|
|
|
|
|
|
48
|
|
|
|
|
|
|
1; |
49
|
|
|
|
|
|
|
|
50
|
|
|
|
|
|
|
__END__ |