Trid is a Go package that provides an interface for the TrID file identifier tool.
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.
-
First, install the TrID command-line tool. You can download it from the official TrID website.
-
Install the Trid Go package:
$ go get github.com/attilabuti/trid@latest
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)
}
}
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)
})
Submit the issues if you find any bug or have any suggestion.
Fork the repo and submit pull requests.
This extension is licensed under the MIT License.