magic: Index | Examples | Files

package magic

import ""

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.



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


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


The file type is GIF89a Image

Package magic imports 2 packages (graph). Updated 2017-10-20. Refresh now. Tools for package owners. This is an inactive package (no imports and no commits in at least two years).