From f83059aa9ccf54f9ab093e7b53243deed74ed4ad Mon Sep 17 00:00:00 2001
From: Darold <gilles@darold.net>
Date: Tue, 21 Aug 2012 20:54:45 +0200
Subject: [PATCH] Add support to bzip2 compressed log file

---
 Makefile.PL      |  4 ++++
 SquidAnalyzer.pm | 12 ++++++++----
 2 files changed, 12 insertions(+), 4 deletions(-)

diff --git a/Makefile.PL b/Makefile.PL
index caf4dd6..5504388 100644
--- a/Makefile.PL
+++ b/Makefile.PL
@@ -127,6 +127,10 @@ my $zcat = `which zcat`;
 chomp($zcat);
 `perl -p -i -e 's#^\\\$ZCAT_PROG.*#\\\$ZCAT_PROG = "$zcat";#' SquidAnalyzer.pm`;
 
+my $bzcat = `which bzcat`;
+chomp($bzcat);
+`perl -p -i -e 's#^\\\$BZCAT_PROG.*#\\\$BZCAT_PROG = "$bzcat";#' SquidAnalyzer.pm`;
+
 WriteMakefile(
 	'DISTNAME'	=> 'SquidAnalyzer',
 	'NAME'		=> 'SquidAnalyzer',
diff --git a/SquidAnalyzer.pm b/SquidAnalyzer.pm
index 625e28e..ef8f65c 100644
--- a/SquidAnalyzer.pm
+++ b/SquidAnalyzer.pm
@@ -15,7 +15,7 @@ use strict;             # make things properly
 
 BEGIN {
 	use Exporter();
-	use vars qw($VERSION $COPYRIGHT $AUTHOR @ISA @EXPORT $ZCAT_PROG);
+	use vars qw($VERSION $COPYRIGHT $AUTHOR @ISA @EXPORT $ZCAT_PROG $BZCAT_PROG);
 	use POSIX;
 	use GD;
 	use GD::Graph;
@@ -35,6 +35,7 @@ BEGIN {
 }
 
 $ZCAT_PROG = "/bin/zcat";
+$BZCAT_PROG = "/bin/bzcat";
 
 # Default translation srings
 my %Translate = (
@@ -149,11 +150,14 @@ sub parseFile
 
 	# Open logfile
 	my $logfile = new IO::File;
-	if ($self->{LogFile} !~ /\.gz/) {
-		$logfile->open($self->{LogFile}) || die "ERROR: Unable to open Squid access.log file $self->{LogFile}. $!\n";
-	} else {
+	if ($self->{LogFile} =~ /\.gz/) {
 		# Open a pipe to zcat program for compressed log
 		$logfile->open("$ZCAT_PROG $self->{LogFile} |") || die "ERROR: cannot read from pipe to $ZCAT_PROG $self->{LogFile}. $!\n";
+	} elsif ($self->{LogFile} =~ /\.bz2/) {
+		# Open a pipe to zcat program for compressed log
+		$logfile->open("$BZCAT_PROG $self->{LogFile} |") || die "ERROR: cannot read from pipe to $BZCAT_PROG $self->{LogFile}. $!\n";
+	} else {
+		$logfile->open($self->{LogFile}) || die "ERROR: Unable to open Squid access.log file $self->{LogFile}. $!\n";
 	}
 
 	my $line = '';