Opened 42 hours ago

Last modified 2 hours ago

#19430 new enhancement

BMimeType::GuessMimeType should check for existing file type attribute

Reported by: grexe Owned by: nobody
Priority: normal Milestone: Unscheduled
Component: Kits/Storage Kit Version: R1/Development
Keywords: Cc:
Blocked By: Blocking:
Platform: All

Description

From looking at the source of MimeType.cpp, there is room for optimization:

When I just want to get the MIME type of a file which *already has* a filetype attribute set, i.e. BEOS:TYPE with a valid MIME type, it should *not* consult the MIME database again but just return the existing type from the attribute value.

Change History (3)

comment:1 by waddlesplash, 41 hours ago

I would expect GuessMimeType to actually guess the type based on contents always. The file's already-set mimetype can be read separately already?

comment:2 by grexe, 18 hours ago

yes that's true, forgot about that. Curiously though, I get different results, e.g. for a Bookmark file:

  • BNodeInfo.GetType() gives me application/x-vnd.Be-bookmark,

but

  • BMimeType::GuessMimeType gives me application/octet-stream (using the same ref as source)
Last edited 15 hours ago by grexe (previous) (diff)

comment:3 by pulkomandy, 2 hours ago

Bookmarks have no contents (only attributes) so the MIME sniffer cannot guess their type based on the content.

The guessing here intentionally does not use the existing MIMe attribute, this allows for example "mimeset -f" to work.

But there could be a higher level API that calls BNodeInfo.GetType(), and only turns to GuessMimeType if the node has no usable attribute.

Note: See TracTickets for help on using tickets.