"be consistent" | |
PerlMonks |
Re: Perl -T vs Mime::Typesby afoken (Chancellor) |
on Sep 19, 2017 at 19:38 UTC ( [id://1199694]=note: print w/replies, xml ) | Need Help?? |
-T tests just a few bytes of the file (see -X). File::Type just guesses a file type by searching for a few magic numbers, like file. Both can't be reliable. If you want to check for a file that contains only ASCII characters, you have to check the entire file. There is no other way. I guess you also want to check for a sane file size, perhaps some hundred kBytes or a few MBytes. On a modern computer, slurping the entire file with that limitation is no big problem. You may want something like this (untested):
If you want significantly larger files, you have to read smaller blocks (perhaps 1 MByte each), and check each block for its "ASCIIness". Abort at the first failed block. Alexander
-- Today I will gladly share my knowledge and experience, for there are no sweeter words than "I told you so". ;-)
In Section
Seekers of Perl Wisdom
|
|