in reply to How to test if a file is gzipped or not

If you have a magic file that should tell what signature a gzip has in order to determine that it is a gzip file.

Naked blocks are fun! -- Randal L. Schwartz, Perl hacker
  • Comment on Re: How to test if a file is gzipped or not

Replies are listed 'Best First'.
Re^2: How to test if a file is gzipped or not
by Happy-the-monk (Canon) on Jun 18, 2024 at 07:42 UTC

    Testing for a file type is called "magic" in linux/unix, hence jwkrahn above mentions the magic file that facilitates translating file signatures to file types.

    In a linux/unix you may test with the file command: file $fileyouwanttotest

    CPAN has File::MimeInfo (and also File::MimeInfo:Magic, but the name is a bit misleading)
    and it works like this:

    use File::MimeInfo; my $mime_type = mimetype('perl-5.38.0.tar.gz'); print("$mime_type\n");

    Cheers, Sören

    Créateur des bugs mobiles - let loose once, run everywhere.
    (hooked on the Perl Programming language)

      There's also File::MMagic and File::Type, and many more.

      map{substr$_->[0],$_->[1]||0,1}[\*||{},3],[[]],[ref qr-1,-,-1],[{}],[sub{}^*ARGV,3]