magic: github.com/mkmueller/magic Index | Examples | Files

package magic

import "github.com/mkmueller/magic"

Package magic will determine the type of file based on the first "magic bytes". The file signatures are not complete, but represent some of the most common file types.

Index

Examples

Package Files

file_signatures.go magic.go

type FileInfo Uses

type FileInfo struct {

    // Name of the file
    Name string

    // Comma delimited list of known extensions for this file type
    Ext []string

    // Description of the file
    Description string

    // Size of the file in bytes
    Size int64
}

FileInfo struct

func FileBytes Uses

func FileBytes(file string) (FileInfo, error)

FileBytes returns a FileInfo struct. The error will be non-nil if the file type cannot be determined or if the file cannot be read.

Example FileBytes

Code:

// Create a tiny GIF image file
fi, err := magic.FileBytes(tiniestGifEver)
if err == nil {
    fmt.Printf("The file type is %s", fi.Description)
}

Output:

The file type is GIF89a Image

Package magic imports 2 packages (graph). Updated 2017-10-20. Refresh now. Tools for package owners.