equal
deleted
inserted
replaced
1 package Imager; |
|
2 use 5.010; |
|
3 use strict; |
|
4 use warnings; |
|
5 use IO::Uncompress::Gunzip qw(gunzip $GunzipError); |
|
6 use autodie qw(:all); |
|
7 use if $^V >= v5.18 => (experimental => 'smartmatch'); |
|
8 |
|
9 our $VERSION = "0.1"; |
|
10 |
|
11 use constant CIPHER => "aes-128-cbc"; |
|
12 |
|
13 sub get_file { |
|
14 my ($base) = @_; |
|
15 foreach (map { "$base$_" } "", qw/.gz .x .gz.x/) { |
|
16 return $_ if -f; |
|
17 } |
|
18 } |
|
19 |
|
20 sub get_block { |
|
21 my ($file, $buffer) = @_; |
|
22 |
|
23 $file = get_file($1) if $file =~ /(.*)\*$/; |
|
24 |
|
25 given ($file) { |
|
26 when (/\.gz\.x$/) { |
|
27 open(my $fh => "openssl @{[CIPHER]} -d -pass $::o{pass} -in $file|"); |
|
28 gunzip($fh => $buffer) or die $GunzipError; |
|
29 } |
|
30 when (/\.gz$/) { gunzip($file => $buffer) or die $GunzipError } |
|
31 when (/\.x$/) { |
|
32 open(my $fh => "openssl @{[CIPHER]} -d -pass $::o{pass} -in $file|"); |
|
33 $$buffer = <$fh>; |
|
34 } |
|
35 default { open(my $fh => $file); sysread $fh => $$buffer, -s $fh } |
|
36 } |
|
37 } |
|
38 |
|
39 1; |
|