add support for magic based identification of files

Based on FR commits:
7b23961d200e3545af3815a8eb40d6d31757024f
f08945a652ae1365ad6bbc5e3dcc8709031b5faf
b6104a74e66ceca98884a6f974485a96a83526a2

From: Saleem Abdulrasool <compnerd@compnerd.org>