bin/imager.fuse
changeset 72 2a7ab8422dd6
parent 51 0b6b92d1eb65
child 74 a8495233e04c
equal deleted inserted replaced
69:c12fa4d32903 72:2a7ab8422dd6
    11 use Pod::Usage;
    11 use Pod::Usage;
    12 use Hash::Util qw(lock_keys);
    12 use Hash::Util qw(lock_keys);
    13 use File::Temp;
    13 use File::Temp;
    14 use DB_File;
    14 use DB_File;
    15 use File::Basename;
    15 use File::Basename;
       
    16 use Imager;
    16 
    17 
    17 my %o = (
    18 my %o = (
    18     debug  => undef,
    19     debug  => undef,
    19     detach => 1,
    20     detach => 1,
    20     tmp    => undef,
    21     tmp    => undef,
   215 
   216 
   216         state %cache;
   217         state %cache;
   217         if (not defined $cache{fn}
   218         if (not defined $cache{fn}
   218             or ($cache{fn} ne $fn))
   219             or ($cache{fn} ne $fn))
   219         {
   220         {
   220 
       
   221             if (-e $fn) {
   221             if (-e $fn) {
   222                 open(my $fh => $fn);
   222 		Imager::get_block($fn => \$cache{data});
   223                 binmode($fh);
       
   224                 local $/ = undef;
       
   225                 $cache{data} = <$fh>;
       
   226             }
   223             }
   227             elsif (-e "$fn.gz") {
   224             elsif (-e "$fn.gz") {
   228                 open(my $fh => "$fn.gz");
   225 		Imager::get_block("$fn.gz" => \$cache{data});
   229                 binmode($fh);
       
   230                 gunzip($fh => \$cache{data})
       
   231                   or die $GunzipError;
       
   232             }
   226             }
   233             elsif (-e "$fn.x") {
   227             elsif (-e "$fn.x") {
   234                 open(
   228 		Imager::get_block("$fn.x" => \$cache{data});
   235                     my $fh =>
       
   236                       "openssl @{[CIPHER]} -d -pass '$o{pass}' -in '$fn.x'|");
       
   237                 binmode($fh);
       
   238                 local $/ = undef;
       
   239                 $cache{data} = <$fh>;
       
   240                 close($fh);
       
   241             }
   229             }
   242             elsif (-e "$fn.gz.x") {
   230             elsif (-e "$fn.gz.x") {
   243                 open(
   231 		Imager::get_block("$fn.gz.x" => \$cache{data});
   244                     my $fh =>
   232             }
   245                       "openssl @{[CIPHER]} -d -pass '$o{pass}' -in '$fn.gz.x'|"
   233 	    else {
   246                 );
   234 		die "Can't get file for $fn";
   247                 binmode($fh);
   235 	    }
   248                 gunzip($fh => \$cache{data})
       
   249                   or die $GunzipError;
       
   250                 close($fh);
       
   251             }
       
   252             elsif (-e "$fn.x.gz") {
       
   253                 warn "$fn.x.gz is depreciated!\n";
       
   254                 open(
       
   255                     my $fh =>
       
   256                       "zcat $fn.x.gz | openssl @{[CIPHER]} -d -pass '$o{pass}'|"
       
   257                 );
       
   258                 binmode($fh);
       
   259                 local $/ = undef;
       
   260                 $cache{data} = <$fh>;
       
   261                 close($fh);
       
   262             }
       
   263             $cache{fn} = $fn;
   236             $cache{fn} = $fn;
   264         }
   237         }
   265 
   238 
   266         return substr($cache{data}, $blockoffset, $length);
   239         return substr($cache{data}, $blockoffset, $length);
   267         die "$fn: $!\n";
       
   268 
   240 
   269     }
   241     }
   270 
   242 
   271     sub writebuffer {
   243     sub writebuffer {
   272         my $path = $IDX . shift;
   244         my $path = $IDX . shift;