Skip to content
/ magic Public

🎩🐇 Toolkit for detecting and verifying file type using magic bytes in pure Golang

License

Notifications You must be signed in to change notification settings

liamg/magic

Repository files navigation

magic

Toolkit for detecting and verifying file type using magic bytes in pure Go.

Support for all file signatures supported by FreeDesktop (and a few more.)

A MIME type, description, and a suggested file extension and icon name are provided for each lookup.

A binary is also included for ease of use.

Binary Usage

$ go install github.com/liamg/magic/cmd/latest@latest
$ magic /path/to/file

Module Usage

See the docs for full details.

package main

import (
	"fmt"
	"os"

	"github.com/liamg/magic"
)

func main() {
	ft, err := magic.IdentifyPath(os.Args[1])
	if err != nil {
		fmt.Printf("\x1b[31mError identifying file: %s\x1b[0m\n", err)
		os.Exit(1)
	}

	fmt.Printf("File         %s\n", os.Args[1])
	fmt.Printf("Description  %s\n", ft.Description)
	fmt.Printf("MIME         %s\n", ft.MIME)
	fmt.Printf("Icon         %s\n", ft.Icon)
}

About

🎩🐇 Toolkit for detecting and verifying file type using magic bytes in pure Golang

Topics

Resources

License

Stars

Watchers

Forks

Sponsor this project

 

Packages

No packages published

Contributors 3

  •  
  •  
  •  

Languages