f3d icon indicating copy to clipboard operation
f3d copied to clipboard

Identify file using magic bytes instead of file extension

Open mwestphal opened this issue 10 months ago • 1 comments

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:

  1. How to discriminates between similar extensions
  2. 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.

mwestphal avatar Feb 22 '25 07:02 mwestphal

I would like to work on this issue

Yogesh9000 avatar Jun 13 '25 18:06 Yogesh9000

Hi @Yogesh9000 , do you need any help moving forward ?

mwestphal avatar Aug 20 '25 08:08 mwestphal

@mwestphal will look into it this week, and will let you know If I need any help.

Yogesh9000 avatar Aug 20 '25 09:08 Yogesh9000

@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.

Yogesh9000 avatar Aug 25 '25 15:08 Yogesh9000

It is not urgent, no worries :)

mwestphal avatar Aug 25 '25 15:08 mwestphal

@Yogesh9000 do you think you could write up the results of your investigation here ?

mwestphal avatar Oct 05 '25 05:10 mwestphal

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.

mwestphal avatar Oct 05 '25 12:10 mwestphal

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.

Yogesh9000 avatar Oct 05 '25 12:10 Yogesh9000

Follow up issue: https://github.com/f3d-app/f3d/issues/2493

mwestphal avatar Oct 05 '25 13:10 mwestphal