#!/usr/bin/perl -w use strict; use Compress::Zlib; my $userfile = '.crazyinsomniac.nodes.hashoaray.dat'; my $tempout = sprintf(".crazy.%010.10s.temp", int(rand(time)) ); for(0..10) { &testshit; &cleanup_file; } sub testshit { &compressor(); for(0..100) { $tempout = sprintf(".crazy.%010.10s.temp", int(rand(time)) ); &decompressor(); } } sub cleanup_file { unlink $tempout if -e $tempout; opendir(DIN,'.') or die "can't opendir . ($!)\n"; my @files = grep {/^.crazy.(\d){10}.temp$/} readdir(DIN); print "trying to delete(",scalar(@files),"):\n", join "\n", @files,"\n"; print 'successfully deleted ',(unlink @files)," files \n"; } sub decompressor { my $x = inflateInit() or die "Cannot create a inflation stream\n"; my ($output, $status,$input); open(FIN , "<".$userfile.'.gz') or die "can't open $userfile($!)\n"; open(FOUT, ">".$tempout) or die "can't open $tempout.gz($!)\n"; binmode FIN; binmode FOUT; while (read(FIN, $input, 4096)) { ($output, $status) = $x->inflate(\$input) ; if( ( $status == Z_OK ) or ( $status == Z_STREAM_END ) ) { print FOUT $output; } last if $status != Z_OK ; } close(FIN); close(FOUT); #unlink $tempout; # you will be deleted # since we don't wanna die before deleting this die "inflation failed\n" unless $status == Z_STREAM_END ; } sub compressor { open(FIN , "<".$userfile) or die "can't open $userfile($!)\n"; open(FOUT, ">".$userfile.'.gz') or die "can't open $userfile.gz($!)\n"; binmode FIN; binmode FOUT; my $deflation_stream = deflateInit() or die "Cannot create a deflation stream\n"; while (read(FIN, $_, 4096)) { my ($output, $status) = $deflation_stream->deflate($_); $status == Z_OK or die "deflation failed\n"; print FOUT $output ; } my ($output, $status) = $deflation_stream->flush(); $status == Z_OK or die "deflation failed\n"; print FOUT $output ; } sub sprinter { for(0..1000) { print sprintf(".crazyinsomniac.%010u.xml_pimp.tpl",rand(time)),"\n"; # print sprintf(".crazyinsomniac.%08.8s.xml_pimp.tpl",rand(time)),"\n"; # its' fine if i use string, but it's supposed to be minimum length for int # but it doesn't pad with d (signed int), but it does with u. # unless it's 9 or > (cause input is always 8 or less) # is this flaw, or what? # this is really fucked up. If i use 8, some strings don't get padded # if i use 9 or greater, they do } }