Blog

Sometimes you find something that's to good not to be shared, I'll try and put some of those on this page.

File recognition

The issue we all run into as developers is how to recognize a file. Well, the first thing we can look at is the file extention (if it's there).
We all can see .zip as a compressed file. Unfortunately, this can't always be trusted, crackers and the lot like to misuse trust in this to get your application to crash or even worse getting hacked into.

The other (better) option is to look at the file headers (magic bytes) of files, you can find some of them at Wikipedia or a more extensive list from Gary Kessler. This will work in most cases to determine the technical type of the file.

Why did I emphasize technical here you might ask. Well, nowadays a lot of file types are compressed, see for example the Microsoft Office files (ex. DOCX as OOXML file type).
Those are nothing more than zip files, you must look inside of those to see which type they are.
Most of the time there is a file in those compressed files which contains information about the file type (ex. OOXML has a file named [Content_Types].xml).

Content Image
Top