Skip to content

Magic number package to read the bytes within a file to learn the format.

License

Notifications You must be signed in to change notification settings

Defacto2/magicnumber

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

11 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Defacto2 / magicnumber

Go Reference Go Report Card

The magicnumber package is to read the bytes within a file to learn of the format or type of file. This is useful for identifying the file without relying on the file extension or MIME type. See the reference documentation for additional usage and examples.

package main

import (
    "fmt"
    "log"
    "os"

    "github.com/Defacto2/magicnumber"
)

func main() {
    file, err := os.Open("example.exe")
    if err != nil {
        log.Fatal(err)
    }
    defer file.Close()

    mn, err := magicnumber.Find(file)
    if err != nil {
        log.Fatal(err)
    }

    fmt.Printf("File type: %s\n", mn.Type)
    fmt.Printf("File extension: %s\n", mn.Extension)
}

About

Magic number package to read the bytes within a file to learn the format.

Resources

License

Stars

Watchers

Forks

Languages