trid

package module
v1.0.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Aug 1, 2024 License: MIT Imports: 9 Imported by: 1

README

Trid

Trid is a Go package that provides an interface for the TrID file identifier tool.

Installation

To use this package, you need to have Go installed on your system. You also need to have the TrID command-line tool installed and accessible in your system's PATH.

  1. First, install the TrID command-line tool. You can download it from the official TrID website.

  2. Install the Trid Go package:

$ go get github.com/attilabuti/trid@latest

Usage

Here's a basic example of how to use the trid package:

package main

import (
    "fmt"
    "log"

    "github.com/attilabuti/trid"
)

func main() {
    // Create a new Trid instance with default options
    t := trid.NewTrid(trid.Options{})

    // Scan a file
    fileTypes, err := t.Scan("/path/to/your/file", 3)
    if err != nil {
        log.Fatalf("Error scanning file: %v", err)
    }

    // Print the results
    for _, ft := range fileTypes {
        fmt.Printf("Extension: %s\n", ft.Extension)
        fmt.Printf("Probability: %.2f%%\n", ft.Probability)
        fmt.Printf("Name: %s\n", ft.Name)
        fmt.Printf("MIME Type: %s\n", ft.MimeType)
        fmt.Printf("Related URL: %s\n", ft.RelatedURL)
        fmt.Printf("Definition: %s\n", ft.Definition)
        fmt.Printf("Remarks: %s\n\n", ft.Remarks)
    }
}

Options

You can configure the Trid instance by providing options:

t := trid.NewTrid(trid.Options{
    Cmd:         "/path/to/trid",         // Command to invoke TrID (default: "trid")
    Definitions: "/path/to/triddefs.trd", // Path to TrID definitions file (default: "")
    Timeout:     60 * time.Second,        // Maximum duration to wait for TrID execution (default: 30 * time.Second)
})

Issues

Submit the issues if you find any bug or have any suggestion.

Contribution

Fork the repo and submit pull requests.

License

This extension is licensed under the MIT License.

Documentation

Overview

This package wraps the TrID command-line tool and parses its output to provide structured information about identified file types.

Index

Constants

This section is empty.

Variables

View Source
var (
	// ErrNoFileSpecified is returned when no file path is provided.
	ErrNoFileSpecified = errors.New("no file specified")

	// ErrNumberOfMatches is returned when the specified number of matches is less than 1.
	ErrNumberOfMatches = errors.New("number of matches must be at least 1")

	// ErrNoDefinitions is returned when no TRiD definitions are available.
	ErrNoDefinitions = errors.New("no TRiD definitions available")

	// ErrEmptyDefPackage is returned when a TRiD definition package is empty.
	ErrEmptyDefPackage = errors.New("TRiD definition package is empty")

	// ErrFileNotFound is returned when the specified file cannot be located or accessed.
	ErrFileNotFound = errors.New("file not found")

	// ErrUnknownFileType is returned when TRiD fails to identify the file type.
	ErrUnknownFileType = errors.New("unknown file type")
)

Functions

This section is empty.

Types

type FileType

type FileType struct {
	Extension   string  // File extension (e.g., ".txt", ".pdf").
	Probability float64 // Probability of the file type match, as a percentage (0-100).
	Name        string  // Descriptive name of the file type.
	MimeType    string  // Mime type of the file (e.g., "text/plain", "application/pdf").
	RelatedURL  string  // URL for additional information about the file type.
	Remarks     string  // Additional notes or comments about the file type from TRiD.
	Definition  string  // Name of the TRiD definition XML file for this file type.
}

FileType represents detailed information about a file type as identified by TrID.

type Options

type Options struct {
	Cmd         string        // Command to invoke the TrID file identifier.
	Definitions string        // Path to the TrID definitions package.
	Timeout     time.Duration // Maximum duration to wait for TrID execution.
}

Options configures the TrID execution parameters.

type Trid

type Trid struct {
	// contains filtered or unexported fields
}

Trid represents a TrID file identifier instance with specific options.

func NewTrid

func NewTrid(opts Options) *Trid

NewTrid creates a new Trid instance with the given options.

func (*Trid) Scan

func (t *Trid) Scan(filePath string, numberOfMatches int) ([]FileType, error)

Scan identifies the file type using TRiD, returning a slice of FileType structs and an error. It takes a file path and the maximum number of potential matches to return.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL