use base qw(Exporter);
our @EXPORT = qw(@comp_supported %comp_supported %comp_ext $comp_regex
- %comp_prog %comp_decomp_prog);
+ %comp_prog %comp_decomp_prog
+ get_compression_from_filename);
our @comp_supported = qw(gzip bzip2 lzma);
our %comp_supported = map { $_ => 1 } @comp_supported;
our %comp_prog = (gzip => 'gzip', bzip2 => 'bzip2', lzma => 'lzma');
our %comp_decomp_prog = (gzip => 'gunzip', bzip2 => 'bunzip2', lzma => 'unlzma');
+sub get_compression_from_filename {
+ my $filename = shift;
+ foreach my $comp (@comp_supported) {
+ if ($filename =~ /^(.*)\.\Q$comp_ext{$comp}\E$/) {
+ return $comp;
+ }
+ }
+ return undef;
+}
+
1;
sub set_filename {
my ($self, $filename) = @_;
- # Identify compression from filename
- my $found = 0;
- foreach my $comp (@comp_supported) {
- if ($filename =~ /^(.*)\.\Q$comp_ext{$comp}\E$/) {
- $found = 1;
- $self->set_compression($comp);
- $self->set_uncompressed_filename($1);
- last;
- }
+ my $comp = get_compression_from_filename($filename);
+ if ($comp) {
+ $self->set_compression($comp);
+ $self->set_compressed_filename($filename);
+ } else {
+ error(_g("unknown compression type on file %s"), $filename);
}
- error(_g("unknown compression type on file %s"), $filename) unless $found;
}
sub set_compressed_filename {