Skip to content

Package Class

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

Package Class

Represents a package containing a collection of file type definitions, version information, creation date, and associated tags.

Namespace: Rheo.Storage.Analyzing.Models

Assembly: Rheo.Storage.dll

Definition

[MessagePackObject]
public partial class Package

Properties

Property Type Description
Version String Gets or sets the version of the package.
CreatedAt DateTime Gets or sets the UTC date and time when the package was created.
Tags PackageTag Gets or sets the tags that describe the state or characteristics of the package.
TotalDefinitions Int32 Gets the total number of file type definitions in the package.
TotalMimeTypes Int32 Gets the total number of distinct MIME types represented in the package definitions.
Definitions List<Definition> Gets or sets the list of file type definitions contained in the package.

Remarks

The Package class serves as a container for file type definition data. It uses MessagePack serialization for efficient storage and transmission of definition databases.

Packages are typically loaded from .rpkg files that contain comprehensive file type identification data.


Property Details

Version

Gets or sets the version of the package.

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

Property Value

String

The version string of the package (e.g., "1.0.0", "2.1.3-beta").


CreatedAt

Gets or sets the UTC date and time when the package was created.

[Key(1)]
public DateTime CreatedAt { get; set; }

Property Value

DateTime

The creation timestamp in UTC.

Remarks

The default value is the current UTC time when the package instance is created.


Tags

Gets or sets the tags that describe the state or characteristics of the package.

[Key(2)]
public PackageTag Tags { get; set; }

Property Value

PackageTag

A combination of flags indicating the package's status and source.

Remarks

Tags can be combined using bitwise operations to indicate multiple states.


TotalDefinitions

Gets the total number of file type definitions in the package.

[JsonIgnore]
[IgnoreMember]
public int TotalDefinitions { get; }

Property Value

Int32

The count of definitions in the Definitions collection.

Remarks

This property is not serialized and is computed dynamically from the Definitions collection.


TotalMimeTypes

Gets the total number of distinct MIME types represented in the package definitions.

[JsonIgnore]
[IgnoreMember]
public int TotalMimeTypes { get; }

Property Value

Int32

The number of unique MIME types across all definitions.

Remarks

This property is not serialized and is computed dynamically by enumerating distinct MIME types from all definitions.


Definitions

Gets or sets the list of file type definitions contained in the package.

[Key(3)]
public List<Definition> Definitions { get; set; }

Property Value

List<Definition>

The collection of file type definitions.


PackageTag Enum

Represents tags that describe the state or characteristics of a package.

[Flags]
public enum PackageTag

Fields

Field Value Description
None 0 No tag is specified.
Stable 1 The package is stable and production-ready.
Beta 2 The package is in beta and may be subject to changes.
Deprecated 4 The package is deprecated and should not be used.
Experimental 8 The package is experimental and may be unstable.
TrID 16 The package is associated with TrID file type definitions.
Validated 32 The package has been validated.

Remarks

The PackageTag enumeration uses the [Flags] attribute, allowing multiple tags to be combined.


Examples

Creating a Package

The following example demonstrates how to create a package with file type definitions:

using Rheo.Storage.Analyzing.Models;

var package = new Package
{
    Version = "1.0.0",
    CreatedAt = DateTime.UtcNow,
    Tags = PackageTag.Stable | PackageTag.Validated,
    Definitions = new List<Definition>
    {
        new Definition
        {
            FileType = "Portable Network Graphics",
            Extensions = new[] { ".png" },
            MimeType = "image/png",
            Signature = new Signature
            {
                Patterns = new List<Pattern>
                {
                    new Pattern { Position = 0, Data = new byte[] { 0x89, 0x50, 0x4E, 0x47 } }
                }
            }
        },
        new Definition
        {
            FileType = "JPEG Image",
            Extensions = new[] { ".jpg", ".jpeg" },
            MimeType = "image/jpeg",
            Signature = new Signature
            {
                Patterns = new List<Pattern>
                {
                    new Pattern { Position = 0, Data = new byte[] { 0xFF, 0xD8, 0xFF } }
                }
            }
        }
    }
};

Console.WriteLine($"Package contains {package.TotalDefinitions} definitions");
Console.WriteLine($"Package contains {package.TotalMimeTypes} MIME types");

Using Package Tags

The following example shows how to work with package tags:

using Rheo.Storage.Analyzing.Models;

var package = new Package
{
    Version = "2.0.0-beta",
    Tags = PackageTag.Beta | PackageTag.TrID
};

// Check if package has specific tags
bool isBeta = package.Tags.HasFlag(PackageTag.Beta);
bool isStable = package.Tags.HasFlag(PackageTag.Stable);

Console.WriteLine($"Is Beta: {isBeta}");      // True
Console.WriteLine($"Is Stable: {isStable}");  // False

// Add a tag
package.Tags |= PackageTag.Validated;

// Remove a tag
package.Tags &= ~PackageTag.Beta;

Querying Package Statistics

The following example demonstrates how to query package information:

using Rheo.Storage.Analyzing.Models;

void DisplayPackageInfo(Package package)
{
    Console.WriteLine($"Package Version: {package.Version}");
    Console.WriteLine($"Created: {package.CreatedAt:yyyy-MM-dd HH:mm:ss} UTC");
    Console.WriteLine($"Total Definitions: {package.TotalDefinitions}");
    Console.WriteLine($"Total MIME Types: {package.TotalMimeTypes}");
    Console.WriteLine($"Tags: {package.Tags}");
    
    // Group definitions by MIME type
    var groupedByMime = package.Definitions
        .GroupBy(d => d.MimeType)
        .OrderByDescending(g => g.Count());
    
    Console.WriteLine("\nTop MIME types:");
    foreach (var group in groupedByMime.Take(5))
    {
        Console.WriteLine($"  {group.Key}: {group.Count()} definitions");
    }
}

Thread Safety

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

See Also

Clone this wiki locally