473,805 Members | 2,027 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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 3562
"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.c om>
Mar 17 '07 #2
On Mar 18, 12:30 am, Jorge Godoy <jgo...@gmail.c omwrote:
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.c omwrote:
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
9097
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 only way I could think of was to determine the extension of the
6
2816
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 mySQL, and I think it may be related to the way I store them. The following line of code is called after an attachment has been identified as a GIF attachment:
0
3245
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 seems to indicate it can't find the <soap:body> element where it's looking for it. We are using the extension <mime:multipartRelated> to define some SOAP attachements in our interface, and the <soap:body> element is inside a subelement of that (per...
1
2791
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 to spot the "broken" links http://www.awin1.com/show.php?mid=1014&linkid=36515&aid=49007 and http://www.awin1.com/awclick.php?mid=1014&linkid=36515&id=49007. Any ideas? BTW, in case the links get fixed before you read the message, the first
5
3006
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 $_FILES superglobal gives the mime type for the file. Is this 100% reliable / accurate? If the mime type says the file type is jpeg is it always right? Two reasons I want to know: 1. Certain types of files mustn't be uploaded, .exe files for example....
0
2162
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 seen that the error is related to the ouput parameter. To my understanding this could be related to the MIME tag. However, I'm by far not a WSDL expert.
1
2890
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 message that I have to send is already in the form of a MIME stream (multipart, attachments and digitally signed), so using the classes of the System.Net.Mail namespace I have to: - parse the MIME - Extract the components - Build a MailMessage...
16
2613
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 previous python experiences: magic names (I felt almost as sad as when I discovered the strange pink worms that eat you in nethack, not to mention the mind flayers - I really hate them). I guess all programming languages have magic names to some...
6
6509
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 the lines mime_magic.debug = Off and mime_magic.magicfile = "C:\Program Files\PHP\extras\magic.mime". Now my phpinfo() says fileinfo support is enabled and mime_magic support is enabled. However, I keep getting this error:
0
9716
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
9596
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
10604
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
10103
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
9179
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
7644
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
5676
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
4316
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
3839
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

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.