473,320 Members | 1,979 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,320 software developers and data experts.

MIME Magic

Hi,

How can I determine the type of a file from "magic bytes", similar to
what the "file" command on unix does? I found

http://docs.python.org/lib/module-mimetypes.html

but this only seems to use the filename (extension) for finding the
type. Any hints?

-Samuel

Mar 17 '07 #1
3 3522
"Samuel" <kn******@gmail.comwrites:
Hi,

How can I determine the type of a file from "magic bytes", similar to
what the "file" command on unix does? I found

http://docs.python.org/lib/module-mimetypes.html

but this only seems to use the filename (extension) for finding the
type. Any hints?
I'd start by taking a look at "file"'s code. :-)

The thing is being able to identify the signatures of several different types
of files. Here's some help for you:
http://www.garykessler.net/library/file_sigs.html

And here's an example of an authoritative source for that table:
http://www.libpng.org/pub/png/spec/1...Structure.html

--
Jorge Godoy <jg****@gmail.com>
Mar 17 '07 #2
On Mar 18, 12:30 am, Jorge Godoy <jgo...@gmail.comwrote:
I'd start by taking a look at "file"'s code. :-)

The thing is being able to identify the signatures of several different types
of files. Here's some help for you:http://www.garykessler.net/library/file_sigs.html

And here's an example of an authoritative source for that table:http://www.libpng.org/pub/png/spec/1...Structure.html
Actually, I am looking for an existing solution because I do not want
to write it from scratch... I hope I am not out of options.

-Samuel

Mar 17 '07 #3
On 18 mar, 00:54, "Samuel" <knipk...@gmail.comwrote:
On Mar 18, 12:30 am, Jorge Godoy <jgo...@gmail.comwrote:
I'd start by taking a look at "file"'s code. :-)
The thing is being able to identify the signatures of several different types
of files. Here's some help for you:http://www.garykessler.net/library/file_sigs.html
And here's an example of an authoritative source for that table:http://www.libpng.org/pub/png/spec/1...Structure.html

Actually, I am looking for an existing solution because I do not want
to write it from scratch... I hope I am not out of options.

-Samuel

python-magic : Python binding for the magic library

This Python library can be use to query /etc/magic information for a
given file in Python.
Mar 18 '07 #4

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

7
by: Phil Powell | last post by:
How do you detect an image MIME type if you know of the image in a directory? For example, I know of: if (is_file("$myImagePath/$myImageName")) { // FIND MIME TYPE BUT HOW I DUNNO } The...
6
by: matt roberts | last post by:
Hello, I am parsing a mailbox using the imap functions, pulling out images attached and putting them into mySQL as BLOB fields. I am having problems displaying images once they are stored in...
0
by: clevariant | last post by:
Hello, I'm tasked with creating a WSDL file that is compatible with .NET's code gen' tool, wsdl.exe. I'm getting an error in the code output saying "Missing soap:body input binding", which...
1
by: ed_spain | last post by:
Hi Everyone, Before I write the script myself, I'm looking for PHP code that checks that a link's content type matches it's contents. I need this for my "broken link" checker script, which fails...
5
by: splodge | last post by:
This may seem like a stupid question but I want to check before I go ahead and build this... I am working on a portal, part of which allows users to upload files. Part of the array within...
0
by: José Joye | last post by:
hello, I have to communicate with a web Service for which I received the WSDL below. When trying to generate the client proxy, it gives me the error (see below). After investigation, I have...
1
by: fabrizio.viggiani | last post by:
I need to send a mail message to an SMTP server. The .net framework provides System.Net.Mail namespace to send an email: - Build a System.Net.Mail.MailMessage and send it using SmtpClient The...
16
by: per9000 | last post by:
Hi, I recently started working a lot more in python than I have done in the past. And I discovered something that totally removed the pretty pink clouds of beautifulness that had surrounded my...
6
by: tinman77 | last post by:
Hello, I'm having a terrible time using the functions finfo_open and finfo_file. I'm using PHP 5 on IIS 5.1 and Windows XP. I have enabled php_mime_magic.dll and php_fileinfo.dll and also added...
0
by: DolphinDB | last post by:
The formulas of 101 quantitative trading alphas used by WorldQuant were presented in the paper 101 Formulaic Alphas. However, some formulas are complex, leading to challenges in calculation. Take...
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
0
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
by: Defcon1945 | last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.