Slash Boxes
NOTE: use Perl; is on undef hiatus. You can read content, but you can't post it. More info will be forthcoming forthcomingly.

All the Perl that's Practical to Extract and Report

use Perl Log In

Log In

[ Create a new account ]

jdavidb (1361)

  (email not shown publicly)

J. David Blackstone has a Bachelor of Science in Computer Science and Engineering and nine years of experience at a wireless telecommunications company, where he learned Perl and never looked back. J. David has an advantage in that he works really hard, he has a passion for writing good software, and he knows many of the world's best Perl programmers.

Journal of jdavidb (1361)

Monday August 11, 2008
08:46 AM

How to determine file type from data stream

[ #37150 ]

I'd like to use MIME::Lite to take arbitrary data as input and send an email with that data as an attachment. I presume that to do this I need to get the MIME type correctly set. So I'm looking for something that can examine that stream of arbitrary, presumably binary, data, and then spit out the MIME type, or else something that I can use to derive the MIME type.

Basically, I'm looking for the "file" command in Perl. I was just remarking with a co-worker the other day how "file"'s database is an incredible resource and how that utility really does an amazing job figuring out what formats things are. It takes a hard job that can never been done perfectly, and does it intelligently. (Actually, that's my definition of artificial intelligence. Maybe "file" is sentient.)

I thought of looking to see if Perl Power Tools has a file command, but seems to be unreachable from my position in time and space, and I'm not really sure I want to download the entire distribution and pore through it, especially since whatever I find probably won't be a library, anyway. I did find a module called MIME::Types, updated as recently as May of this year, but it doesn't really do this job; it will give me a MIME type based on a file extension or based on a filename, which does me no good since STDIN doesn't come with a filename. :) If I had a filename, I most likely wouldn't need the module I'm looking for. The docs for MIME::Types mentions a File::TypeInfo module, but that doesn't seem to exist on CPAN at this point in time.

Even if I need to do this some other way, or don't need to do this at all to achieve my goal, I'm still curious if anything like this exists.

The Fine Print: The following comments are owned by whoever posted them. We are not responsible for them in any way.
More | Login | Reply
Loading... please wait.