How does computer understand whether some file is text, video, image. As it only understands binary at the end of the day ?

306 views

I tried going through various articles and videos available online, but couldn’t really understand, properly!!

In: 0

9 Answers

Anonymous 0 Comments

The simplest way is to just look at the file name extension, the part of the file name after the period. It is often common for files to come with what is known as a MIME file type string, HTTP, email, etc. does this. This will again tell the computer what type of file it is. But these are just hints and might be wrong at the end of the day.

There are tools which are able to identify a lot of different file types by looking at its content. It is very common for file types to have certain “magic numbers” in them which are there to help identify the file type. If you open a file in a text editor it often say the file type right in the beginning. So just a simple database of these magic numbers and their locations within the file goes a long way to identify the file type. And if a file type does not have an intentional magic number identifying it there are often very common numbers in the file which can help identify the file type. At this point we have covered almost all the file types out there but it is still possible to do even more advanced pattern matching and trying to parse the content.

You are viewing 1 out of 9 answers, click here to view all answers.