Filetype question

Hello,

I’ve recently had to work on a filetype with the native app StreamAudio which is handling “playlist” file :

I was wondering how Haiku was determining this filetype because my file as no extension and no mime type info :

It seems the command “file” is able at least to detect it as a “PLS playlist”, is it because of the content of the file which is having a “[playlist]” tag ?

Working on an upcoming article about StreamRadio native app, that’s why I’m wondering :slight_smile:

Haiku stores this information in extended attributes.
Your second command, mimeset, does not determine wether a file has mime type info. Your info dialog above on the other hand is correct.

Storing the mime type this way allows there to be a couple methods to determine the mimetype:

  1. Pre-determined: The application that saved this file has set the mimetype
  2. Carried-over: A remote server has specified this mime type and it was carried over (E-Mail MIME or http)
  3. Sniffed: there was no mime provided and tracker sniffs it as soon as you click on it based on file content (main stream)

To check out the mimetype you have to look at the attributes.
For example, a text file on my computer:

~> listattr error.txt 
File: error.txt
        Type       Size  Name                                
----------------------------------------------------------
      Int-32         4  "be:encoding"
 MIME String        11  "BEOS:TYPE"
      Int-32         4  "wrap"
      Int-32         4  "alignment"
    Raw Data       160  "styles"
      'RECT'        16  "StyledEdit-info"
      Int-32         4  "be:caret_position"

203 bytes total in attributes. 

These attributes are sometimes app specific or global. Here for example styles and StyledEdit-info are stylededit specific, be:caret_position is specific to “any editor”. wrap an alignment probably too but I’m not sure.

The interesting attribute here for you is BEOS:TYPE
You can inspect this with catattr, for example:

~> catattr BEOS:TYPE error.txt 
error.txt : 'MIMS' : text/plain

Where MIMS is the type of the content, and text/plain is the content, and BEOS:TYPE is the label/name of the content.

This example is a plain text file.

Another example I have is a html document:

~> catattr BEOS:TYPE index.html 
index.html : 'MIMS' : text/html

Further reading:
https://www.haiku-os.org/docs/userguide/en/workshop-filetypes+attributes.html

https://www.haiku-os.org/docs/userguide/en/applications/cli-apps.html

https://www.haiku-os.org/docs/userguide/en/attributes.html#attributes-terminal

1 Like

Super clear.

Indeed catattr BEOS:TYPE was the command I was searching for.

Thanks !

Yes, the “file” command comes with its own database (in the file_data package) with various rules to identify files. This is independant of the wqay it is done in Haiku and BeOS.

For completeness, this is done in various other cases, not only Tracker, and in particular, this is also what the mimeset command does: detect the file content, and store the result in the attribute so it is remembered.

Ok got it. I’ve just made a quick check to confirm the understanding :

echo "sample file" >sample

No attribute :

listattr ./sample 
File: ./sample
        Type       Size  Name                                
----------------------------------------------------------

0 bytes total in attributes.

However the “file” command is able to recognize as below (without attribute) :

file ./sample 
./sample: ASCII text

Opening the file in the Tracker or doing the below :

mimeset ./sample

Then now we have attributes:

listattr ./sample 
File: ./sample
        Type       Size  Name                                
----------------------------------------------------------
 MIME String        11  "BEOS:TYPE"

11 bytes total in attributes.

And MIME type is now attached to the “sample” file :

catattr BEOS:TYPE ./sample 
./sample : 'MIMS' : text/plain