Search code examples
objective-cxcodemacosencodingmime-types

How can i determine if a file is binary or text?


I'm writing an application where i need to determine if the files provided from the user are text or not because i'm performing a search within them.

I'm not basing on the extension, cause i want to search also in source code files for example, or any other file that have a textual content (even for not well known extensions).

Is there a way to determine if a file is text or not?


Solution

  • Thanks everyone for the solutions provided! I just found a framework that seems to do the job quite well!

    I leave here a link for reference: https://github.com/aidansteele/MagicKit