Skip to main content

Crate magika

Crate magika 

Source
Expand description

Determines file content types using AI.

This library indirectly depends on the ONNX Runtime through the ort crate. The final user is responsible to make sure the ONNX Runtime is available. The ort crate provides many options in this regard. The simplest option is to enable the default cargo features of the ort crate by adding the following dependency to the Cargo.toml file of the final binary:

[dependencies]
ort = "=2.0.0-rc.12"

§Examples

// A Magika session can be used multiple times across multiple threads.
let mut magika = magika::Session::new()?;

// Files can be identified from their path.
assert_eq!(magika.identify_file_sync("src/lib.rs")?.info().label, "rust");

// Contents can also be identified directly from memory.
let result = magika.identify_content_sync(&b"#!/bin/sh\necho hello"[..])?;
assert_eq!(result.info().label, "shell");

Structs§

Builder
Configures and creates a Magika session.
Features
Features to identify a file using AI.
InferredType
Content type identified using AI.
Session
A Magika session to identify files.
TypeInfo
File type information.

Enums§

ContentType
Content types for regular files.
Error
Errors returned by Magika functions.
FeaturesOrRuled
Result of features extraction.
FileType
File types.
OverwriteReason
Reason to overwrite an inferred content type.

Constants§

MODEL_MAJOR_VERSION
Model major version.
MODEL_NAME
Model name (only comparable with equality).

Traits§

AsyncInput
Asynchronous abstraction over file content.
SyncInput
Synchronous abstraction over file content.

Type Aliases§

Result
Result type of Magika functions.