lib/Imager.pm
changeset 72 2a7ab8422dd6
child 74 a8495233e04c
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/lib/Imager.pm	Wed Aug 17 12:10:20 2011 +0200
@@ -0,0 +1,29 @@
+package Imager;
+use 5.010;
+use strict;
+use warnings;
+use IO::Uncompress::Gunzip qw(gunzip $GunzipError);
+use autodie qw(:all);
+
+use constant CIPHER => "aes-128-cbc";
+
+sub get_block {
+    my ($file, $buffer) = @_;
+
+    given ($file) {
+        when (/\.gz\.x$/) {
+            open(my $fh => "openssl @{[CIPHER]} -d -pass $::o{pass} -in $file|");
+            local $/ = undef;
+            gunzip($fh => $buffer) or die $GunzipError;
+        }
+        when (/\.gz$/) { gunzip($file => $buffer) or die $GunzipError }
+        when (/\.x$/) {
+            open(my $fh => "openssl @{[CIPHER]} -d -pass $::o{pass} -in $file|");
+            local $/ = undef;
+            $$buffer = <$fh>;
+        }
+        default { open(my $fh => $file); local $/ = undef; $$buffer = <$fh> }
+    }
+}
+
+1;