Linux ip-172-26-7-228 5.4.0-1103-aws #111~18.04.1-Ubuntu SMP Tue May 23 20:04:10 UTC 2023 x86_64
Your IP : 3.133.143.118
#!/usr/bin/perl
no lib '.';
use strict;
use warnings;
use autodie;
while (my $line = <>) {
my ($file, $type) = $line =~ (m/^(.*?)\x00(.*)$/o);
if ($file =~ m/\.gz$/o && -f $file && !-l $file && $type !~ m/compressed/o)
{
# While file could be right, it is unfortunately
# regularly wrong here as well; double check the type
my $text = '';
my $buff;
open(my $gzf, '<', $file);
# We need to read at least 9 bytes
if (sysread($gzf, $buff, 1024) >= 9) {
# translation of the unpack
# nn nn , NN NN NN NN, nn nn, cc - bytes read
# $magic, __ __ __ __, __ __, $comp - variables
my ($magic, undef, undef, $comp) = unpack('nNnc', $buff);
if ($magic == 0x1f8b){ # the gzip file magic
$text = 'gzip compressed data';
# 2 for max compression; RFC1952 suggests this is a
# flag and not a value, hence the bit and operation
if (($comp & 2) == 2){
$text = "$text, max compression";
}
}
}
close($gzf);
$type = "$type, $text" if $text;
}
printf "%s%c%s\n", $file, 0, $type;
}
# Local Variables:
# indent-tabs-mode: nil
# cperl-indent-level: 4
# End:
# vim: syntax=perl sw=4 sts=4 sr et
|