Haiku API Bindings
MimeType
Not logged in

Documentation | StorageKit | MimeType

SYNOPSIS

Perl

use HaikuR1::MimeType;

my $type = HaikuR1::MimeType->new($mime_string);
$type->Install();

Python

from HaikuR1.StorageKit import MimeType

type = MimeType(mime_string)
type.Install()

DESCRIPTION

Exposes the BMimeType object.

For more information on MimeType, see the Be Book class description, the Be Book overview, and the Haiku Book class description.

For more information on mime types in general, see Media types on Wikipedia.

METHODS

Constructor

Creates a MimeType.

Perl

HaikuR1::MimeType->new($mimeType);
HaikuR1::MimeType->new();

Python

MimeType(mimeType)
MimeType()

App hint

GetAppHint

SetAppHint

Gets or sets the application hint for the mime type. This is a path on the file system, not an application signature, so this may break if the file is moved.

Perl

$mimetype->GetAppHint();
$mimetype->SetAppHint($ref);

Python

mimetype.GetAppHint()
mimetype.SetAppHint(ref)

Attribute info

GetAttrInfo

SetAttrInfo

Gets or sets a native list of native maps containing the attributes that files of this type will normally have. The maps will have the following fields:

Note: The C++ version of this method passes the information in a Message.

Perl

$mimetype->GetAttrInfo();
$mimetype->SetAttrInfo($info);

Python

mimetype.GetAttrInfo()
mimetype.SetAttrInfo(info)

Descriptions

GetShortDescription

SetShortDescription

GetLongDescription

SetLongDescription

Gets or sets a description for the mime type.

The suggested size difference between the names is not enforced; both values have the same length limit - B_MIME_TYPE_LENGTH (which is a limit on the number of bytes, not on the number of characters).

Perl

$mimetype->GetShortDescription();
$mimetype->SetShortDescription($description);
$mimetype->GetLongDescription();
$mimetype->SetLongDescription($description);

Python

mimetype.GetShortDescription()
mimetype.SetShortDescription(description)
mimetype.GetLongDescription()
mimetype.SetLongDescription(description)

File extensions

GetFileExtensions

SetFileExtensions

Gets or sets a list of file extensions that this type would usually have, as a native list of strings.

Note: The C++ version of this method passes the information in a Message.

Perl

$mimetype->GetFileExtensions();
$mimetype->SetFileExtensions($extensions);

Python

mimetype.GetFileExtensions()
mimetype.SetFileExtensions(extensions)

GetSupportingApps

Returns a list of applications that handle this file type, as a native map with three fields:

The sub applications come before the super applications in the list.

Note: The C++ version of this method passes the information in a Message.

Perl

$mimetype->GetSupportingApps();

Python

mimetype.GetSupportingApps()

Icons

GetIcon

SetIcon

GetIconForType

SetIconForType

Gets the mime type's icon. If you pass a size, then it returns a Bitmap; otherwise, it the raw icon data.

The Type versions are for applications, and work on the icon that the application will use for the given type. (The MimeType object is the application, and type is the desired type.)

Perl

$mimetype->GetIcon($size, $colorSpace);
$mimetype->GetIcon();
$mimetype->SetIcon($icon);
$mimetype->SetIcon($data);
$mimetype->GetIconForType($type, $size, $colorSpace);
$mimetype->GetIconForType();
$mimetype->SetIconForType($type, $icon);
$mimetype->SetIconForType($type, $data);

Python

mimetype.GetIcon(size, colorSpace)
mimetype.GetIcon()
mimetype.SetIcon(icon)
mimetype.SetIcon(data)
mimetype.GetIconForType(type, size)
mimetype.GetIconForType(type, size, colorSpace)
mimetype.SetIconForType(type, icon)
mimetype.SetIconForType(type, data)

Install

Delete

IsInstalled

These methods operate on the system mime type database. (You can examine the contents of this databse via the FiletTypes preflet.)

Perl

$mimetype->Install();
$mimetype->Delete();
$mimetype->IsInstalled();

Python

mimetype.Install()
mimetype.Delete()
mimetype.IsInstalled()

Preferred App

GetPreferredApp

SetPreferredApp

Gets or sets the preferred application for the mime type.

Perl

$nodeinfo->GetPreferredApp($verb);
$nodeinfo->SetPreferredApp($signature, $verb);

Python

nodeinfo.GetPreferredApp(verb)
nodeinfo.SetPreferredApp(signature, verb)

SetTo

Unset

Updates the MimeType object to refer to a different mime type, or to no mime type.

Perl

$mimetype->SetTo($mimeType);
$mimetype->Unset();

Python

mimetype.SetTo(mimeType)
mimetype.Unset()

Sniffer rules

GetSnifferRule

SetSnifferRule

Sniffer rules are used by the system to guess the mime type a file or byte string.

Perl

$mimetype->GetSnifferRule();
$mimetype->SetSnifferRule($rule);

Python

mimetype.GetSnifferRule()
mimetype.SetSnifferRule(rule)

Supertype

IsSupertypeOnly

GetSupertype

Contains

Methods for working with supertypes.

Note: Contains will return true not only when the current MimeType contains the given MimeType, but also when both MimeTypes reprsent the same mime type.

Perl

$mimetype->IsSupertypeOnly();
$mimetype->GetSupertype();
$mimetype->Contains($type);

Python

mimetype.IsSupertypeOnly()
mimetype.GetSupertype()
mimetype.Contains(type)

Type

Returns the mime string for the type represented by the MimeType object.

Perl

$mimetype->Type();

Python

mimetype.Type()

CLASS METHODS

CheckSnifferRule

Determines whether a sniffer rule is valid.

Here are some explanatory examples from haiku/headers/private/storage/sniffer/Parser.h (in the git repo) or ... (if you have the development headers on your installation of Haiku). (In the same file you will also find the grammar from which I pulled the rules above.)

Here are some real examples, from sniffers included with Haiku:

Perl

HaikuR1::MimeType->CheckSnifferRule($rule);

Python

MimeType.CheckSnifferRule(rule)

GetWildcardApps

Acts like GetSupportingApps, but returns a list of signatures for applications that support any file type. (The super value will always be 0.)

Perl

HaikuR1::MimeType->GetWildcardApps();

Python

MimeType.GetWildcardApps()

GuessMimeType

Guesses the mime type for a file or a byte string.

Perl

HaikuR1::MimeType->GuessMimeType(path => $path);
HaikuR1::MimeType->GuessMimeType(data => $data);

Python

MimeType.GuessMimeType(path = path)
MimeType.GuessMimeType(data = data)

Installed types

GetInstalledTypes

GetInstalledSupertypes

Gets or sets a list of installed types, as a native list of strings.

Note: The C++ version of this method passes the information in a Message.

Perl

HaikuR1::MimeType->GetInstalledTypeForSupertype($supertype);
HaikuR1::MimeType->GetInstalledSupertypes();

Python

MimeType.GetInstalledTypeForSupertype(supertype)
MimeType.GetInstalledSupertypes()

IsValid

Returns true if the represented type is valid, or false if it is not.

The algorithm to determne validity is simple:

Perl

HaikuR1::MimeType->IsMimeTypeValid($mimeType);
$mimetype->IsValid();

Python

MimeType.IsMimeTypeValid(mimeType)

Perl

The Perl version functions as both a class method and an instance method, so you call the method on an object instead of passing it as the first parameter.

MIME Monitor

StartWatching

StopWatching

These methods track changes to the MIME database.

Notifications will come in the form of a Message with a what value of B_META_MIME_CHANGED and a field called opcode, with the following fields:

Perl

HaikuR1::MimeType->StartWatching($target);
HaikuR1::MimeType->StopWatching($target);

Python

MimeType.StartWatching(target)
MimeType.StopWatching(target)

OPERATORS

==

Returns true if the MimeType objects refer to the same mime type. Can also be used to compare a MimeType object to a mime type string.

CONSTANTS

App verbs

Perl

use HaikuR1::MimeType qw(:app_verb)

Python

Python does not support export tags.

MIME actions

Perl

use HaikuR1::MimeType qw(:action)

Python

Python does not support export tags.

MIME changes

The first item in the list is the what value in a MIME change notification Message. The remaining items are the change indicators.

Perl

use HaikuR1::MimeType qw(:change)

Python

Python does not support export tags.

MIME types

Perl

use HaikuR1::MimeType qw(:types)

Python

Python does not support export tags.