Identify file using magic bytes instead of file extension
Is your feature request related to a problem? Please describe. F3D is able to read many file formats and rely on the extension to identify which reader/plugin to use. That works well however it has strong limitations:
- How to discriminates between similar extensions
- How to pick right reader when reading file from stream (https://github.com/f3d-app/f3d/issues/1100)
Lets use magic byte logic to identify file format as well
Describe the solution you'd like Use libmagic to identify files and check if a reader can read a file or not. This may need some changes in VTK (CanReadFile) or may be a F3D only solution.
I would like to work on this issue
Hi @Yogesh9000 , do you need any help moving forward ?
@mwestphal will look into it this week, and will let you know If I need any help.
@mwestphal I had some work come up last week and I’m tied up this week as well, so it may be a while before I can get to this issue. If this is an urgent issue, you’re welcome to give it a try in the meantime or assign it to someone else.
It is not urgent, no worries :)
@Yogesh9000 do you think you could write up the results of your investigation here ?
So an investigation was done by @Yogesh9000 and libmagic is not magic after all and cannot do everything. As VTK aleasy as the CanReadFile API, lets use that instead.
As @mwestphal mentioned libmagic is not magic and does not work for identifying all the filetypes f3d supports. Libmagic works for binary filetypes by identifying the magic number, but it fails for non-binary filetypes such as gltf which are just text files(json, csv, xml, etc). For non-binary filetypes we would need to perform parsing of the file to determine it's filetype with any kind of confidence.
Follow up issue: https://github.com/f3d-app/f3d/issues/2493