2

Is it possible to check what type of data does represent string binary file?

For example: We have binary data read from image file (f.e. example.jpg). Can we guess that this binary data represent image file? If yes, how we can do that?

2
  • magic numbers typically identify the type of file ... its usually the first n bytes of a file ... Commented Dec 5, 2012 at 22:39
  • Are you just trying to distinguish the type of image files among a few specific types (JFIF, PNG, TIFF, etc.), or the file of any file at all, with no restrictions? If you stick to something specific, you can get more specific answers (e.g., distinguish animated GIFs from multi-image poster GIFs, or TIFF with JPEG compression from TIFF with RLE compression, or whatever), and with more confidence. If it just has to work with "almost everything", you can only get pretty good answers—in which case, @Xymostech has the right solution. Commented Dec 5, 2012 at 22:45

1 Answer 1

3

You could look at the python-magic library. It seems to do what you want (although I've never used it myself).

Sign up to request clarification or add additional context in comments.

1 Comment

+1. I actually have used it, and it works great. Or, at least, as well as the Unix file command, which is about as well as anything general-purpose is going to work.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.