--- a/bin/imager.compress Sat Jul 25 17:16:13 2015 +0200
+++ /dev/null Thu Jan 01 00:00:00 1970 +0000
@@ -1,113 +0,0 @@
-#! /usr/bin/perl
-
-use 5.010;
-use strict;
-use warnings;
-use POSIX qw(strftime);
-use autodie qw(:all);
-use File::Basename;
-use File::Temp;
-use IO::Compress::Gzip qw(gzip $GzipError :level :strategy);
-use IO::Uncompress::Gunzip qw(gunzip $GunzipError);
-use Getopt::Long;
-use Pod::Usage;
-use File::Find;
-
-use constant THRESHOLD => 0.90;
-use constant LEVEL => Z_BEST_SPEED;
-
-MAIN: {
-
- GetOptions(
- "h|help" => sub { pod2usage(-verbose => 1, -exit => 0) },
- "m|man" => sub {
- pod2usage(
- -verbose => 2,
- -exit => 0,
- -noperldoc => system("perldoc -V 1>/dev/null 2>&1")
- );
- },
- )
- and @ARGV
- or pod2usage;
-
- find(
- sub {
- say "dir $File::Find::name" and return if -d;
- return if not (-f and /^[\da-f]{32}(?:\.x\.gz|\.gz)?$/);
- #print STDERR ".";
-
- open(my $fh, $_);
- my ($buffer, $zbuffer);
- my ($tmp);
-
- if (/\.gz$/) {
- sysread $fh => $zbuffer, -s $fh;
- gunzip(\$zbuffer => \$buffer)
- or die $GunzipError;
-
- if (!length($buffer)) {
- warn "?? zero length after decompression: $_\n";
- return;
- }
- return if length($zbuffer) / length($buffer) < THRESHOLD;
-
- $tmp = File::Temp->new(DIR => ".", TEMPLATE => ".tmp-XXXXXX");
- syswrite $tmp => $buffer;
- rename $tmp->filename => basename($_, ".gz");
- say "uncompressed $_";
- #print "+";
-
- }
- else {
- sysread $fh => $buffer, -s $fh;
- gzip(
- \$buffer => \$zbuffer,
- -Minimal => 1,
- -Level => Z_BEST_SPEED,
- -Strategy => Z_FILTERED
- ) or die $GzipError;
- return if length($zbuffer) / length($buffer) >= THRESHOLD;
-
- $tmp = File::Temp->new(DIR => ".", TEMPLATE => ".tmp-XXXXXX");
- syswrite $tmp => $zbuffer;
- rename $tmp->filename => "$_.gz";
- say " compressed $_";
- #print STDERR "-";
- }
-
- close $tmp;
- map { unlink } $tmp, $_;
-
- return 0;
-
- },
- @ARGV
- );
-
- exit 0;
-
-}
-
-__END__
-
-=head1 NAME
-
- imager.compress - compress or decompress the blocks
-
-=head1 SYNOPSIS
-
- imager.compress {dir}
-
-=head1 DESCRIPTION
-
-B<imager.compress> checks all files below the I<dir[s]>.
-
-If compression saves more then 10% it will save the compressed block,
-otherwise the uncompressed.
-
-=cut
-
-
-
-