h2non / filetype.py

Small, dependency-free, fast Python package to infer binary file types checking the magic numbers signature
https://h2non.github.io/filetype.py
MIT License
663 stars 113 forks source link

Add support to txt file #169

Closed ghrimx closed 10 months ago

ghrimx commented 11 months ago

Great package! would it be possible to add support to txt file?

avibn commented 10 months ago

Hey, I was also looking into this today, and it seems plain text files don't typically have magic numbers. A way might be to check for a byte order mark, which could provide a close "guess".

h2non commented 10 months ago

Nope. Only binary files are supported in this library. TXT cannot be reliably detected, however, you can presume it by checking the file extension and reading the first bytes to the file content is readable text.