Skip to content

Definition Class

Naveen Dharmathunga edited this page Jan 19, 2026 · 1 revision

Definition Class

Represents a file type definition, including associated extensions, MIME type, and related metadata.

Namespace: Rheo.Storage.Analyzing.Models

Assembly: Rheo.Storage.dll

Definition

[MessagePackObject]
public partial class Definition

Properties

Property Type Description
FileType String Gets or sets the file type associated with the type definition.
Extensions String[] Gets or sets the file extension associated with the type definition.
MimeType String Gets or sets the MIME type associated with the content.
Remarks String Gets or sets additional information or notes related to the current context.
Signature Signature Gets or sets the digital signature associated with the current object.
PriorityLevel Int32 Gets or sets the priority level of the definition.

Remarks

The Definition class is used to describe file type characteristics and is typically populated from file definition packages. It uses MessagePack serialization for efficient storage and transmission.

This class is commonly used in file analysis scenarios where files need to be identified based on their binary signatures, file extensions, and MIME types.


Property Details

FileType

Gets or sets the file type associated with the type definition.

[Key(0)]
public string FileType { get; set; }

Property Value

String

The name or description of the file type (e.g., "Portable Network Graphics", "ZIP Archive").

Remarks

This property provides a human-readable name for the file format. It is typically used for display purposes and logging.


Extensions

Gets or sets the file extension associated with the type definition.

[Key(1)]
public string[] Extensions { get; set; }

Property Value

String[]

An array of file extensions associated with this file type (e.g., [".png"], [".zip", ".jar"]).

Remarks

Multiple extensions may be associated with a single file type. Extensions typically include the leading dot character.


MimeType

Gets or sets the MIME type associated with the content.

[Key(2)]
public string MimeType { get; set; }

Property Value

String

The MIME type string (e.g., "image/png", "application/zip").

Remarks

The MIME type follows the standard format defined in RFC 6838. It is used for content type identification in HTTP headers and other protocols.


Remarks

Gets or sets additional information or notes related to the current context.

[Key(3)]
public string Remarks { get; set; }

Property Value

String

Additional notes, version information, or context about the file type.


Signature

Gets or sets the digital signature associated with the current object.

[Key(4)]
public Signature Signature { get; set; }

Property Value

Signature

A Signature object containing patterns and strings used to identify this file type.

Remarks

The signature contains the byte patterns (magic numbers) and optional string sequences used by the file analyzer to identify files of this type.


PriorityLevel

Gets or sets the priority level of the definition.

[Key(5)]
public int PriorityLevel { get; set; }

Property Value

Int32

The priority level, where higher values indicate higher priority. Default is 0.

Remarks

When multiple definitions match a file, the priority level can be used to determine which definition should be preferred.


Methods

ToString()

Returns a string representation of the definition.

public override string ToString()

Returns

String

A string in the format: FileType (MimeType) [Extensions]

Examples

var definition = new Definition
{
    FileType = "Portable Network Graphics",
    MimeType = "image/png",
    Extensions = new[] { ".png" }
};

Console.WriteLine(definition.ToString());
// Output: Portable Network Graphics (image/png) [.png]

Examples

Creating a File Type Definition

The following example demonstrates how to create a file type definition:

using Rheo.Storage.Analyzing.Models;

var pngDefinition = new Definition
{
    FileType = "Portable Network Graphics",
    Extensions = new[] { ".png" },
    MimeType = "image/png",
    Remarks = "PNG image format with lossless compression",
    Signature = new Signature
    {
        Patterns = new List<Pattern>
        {
            new Pattern { Position = 0, Data = new byte[] { 0x89, 0x50, 0x4E, 0x47 } }
        }
    },
    PriorityLevel = 100
};

Using Definitions in File Analysis

The following example shows how definitions are typically used:

using Rheo.Storage.Analyzing;
using Rheo.Storage.Analyzing.Models.Result;

string filePath = @"C:\Images\photo.png";
AnalysisResult result = FileAnalyzer.AnalyzeFile(filePath);

if (result.Definitions.Count > 0)
{
    var topMatch = result.Definitions.Peek();
    var definition = topMatch.Subject;
    
    Console.WriteLine($"File Type: {definition.FileType}");
    Console.WriteLine($"MIME Type: {definition.MimeType}");
    Console.WriteLine($"Extensions: {string.Join(", ", definition.Extensions)}");
}

Thread Safety

This class is not thread-safe. When accessing instances from multiple threads, use appropriate synchronization mechanisms.

See Also

Clone this wiki locally