Re: [GNOME VFS] Re: using deprecated gnome_mime instead of gnome_vfs_mime (was file moniker patch)



Michael Meeks <michael helixcode com> writes:

> Hi,
> 
> On Thu, 30 Nov 2000, Darin Adler wrote:
> > Why do you call the MIME database and MIME sniffing a trivial hack? 
> > It's a piece of code that's hard to get right, and we've been working
> > on making it better for months.
>   
>         This reminds me ( on a totaly different track ); I was recently
> reading through some parts of the gnome-vfs api and I noticed these APIs:
> 
> const char *gnome_vfs_get_mime_type_for_buffer
>                 (GnomeVFSMimeSniffBuffer *buffer);
> 
>         I assume this function uses the mime magic information to try and
> determine the type, and returns NULL if it can't characterize it
> precicely. Then I saw:
> 
> gboolean gnome_vfs_sniff_buffer_looks_like_text   
>                 (GnomeVFSMimeSniffBuffer *buffer);
> 
>         And I thought fair enough, perhaps text is a very special case for
> sniffing; then I saw:
> 
> gboolean    gnome_vfs_sniff_buffer_looks_like_mp3 
>                 (GnomeVFSMimeSniffBuffer *buffer);
>   

Text files and MP3 files are both formats that, for various reasons,
can't be detected with magic number sniffing. This is why they need
special algorithms to handle detection.

We'd like to avoid there being more such file formats in the future
since they detract from performance.

>         And I was slightly worried. Are we going to gather a great series
> of looks_like_my_grandma type calls ? or should the (fuzzy) sniffing API  
> be something like:
>   
> gboolean gnome_vfs_sniff_buffer_looks_like (buffer, char *mime_type);
> 
>         So; then I looked at the implementation to try and work out what's
> going on and I see in the get_mime_type_for_buffer function:
>   
>         /* if no match, try the algorithmic sniffers */
>         if (gnome_vfs_sniff_buffer_looks_like_mp3 (buffer)) {
>                 return "audio/x-mp3";
>         }
>   
>         But no sniff for text.

Yes, text sniffing is only done after extension-based mime type
detection (this is so .c files get detected as text/x-c rather than
text/plain and the like).

>         And it looks ( from the comment ) as if a more general framework  
> was intended, with perhaps pluggable mime type sniffers; is this the
> case? it would seem more reasonable ( to me ), to register a list of
> sniffer functions that could be handled genericly, perhaps with a degree  
> of certainty ranking depending on how smelly the stream is to them ?

It's not really worthwhile. The vast majority of file types are
sniffable with normal magic number detection and we don't want to
encourage people to write ones that aren't.

 - Maciej




[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]