No description
Find a file
2025-07-11 21:37:50 -04:00
LICENSE initial 2025-07-11 21:19:43 -04:00
magic.odin remove unnecessary types on constants 2025-07-11 21:37:50 -04:00
README.md Update README.md 2025-07-11 21:29:20 -04:00

magic

Odin bindings for libmagic, the library behind the Unix file command.

This package allows you to identify file types and MIME types using libmagic directly from Odin.

Requirements

  • libmagic installed (usually via your system package manager)

Usage

import "magic"
import "core:fmt"

main :: proc() {
    cookie := magic.open(magic.NONE)
    if cookie == nil {
        fmt.eprintln("Error allocating cookie")
        return
    }
    defer magic.close(cookie)

    if magic.load(cookie, nil) != 0 {
        fmt.eprintfln("Error loading magic database: %s", magic.error(cookie))
        return
    }

    result := magic.file(cookie, "example.png")

    if result == nil {
        fmt.eprintfln("Error: %s\n", magic.error(cookie))
        return
    }

    fmt.printfln("File type: %s", result)
}