A look at h2non/filetype: 2.3k stars on GitHub, written primarily in Go, tracked under the Backend category. Fast, dependency-free Go package to infer binary file types based on the magic numbers header signature
Snapshot summary built from the project's own GitHub metadata — there's no written TopGit review yet. The page will update automatically when a full review is published.
WHY NO REVIEW YET
TopGit writes full reviews for the most-starred, most-requested repositories. This page is a snapshot until then — see the READ ME tab for the original README in full.
package main
import (
"fmt"
"os"
"github.com/h2non/filetype"
)
func main() {
buf, _ := os.ReadFile("sample.jpg")
if filetype.IsImage(buf) {
fmt.Println("File is an image")
} else {
fmt.Println("Not an image")
}
}
Supported type
package main
import (
"fmt"
"github.com/h2non/filetype"
)
func main() {
// Check if file is supported by extension
if filetype.IsSupported("jpg") {
fmt.Println("Extension supported")
} else {
fmt.Println("Extension not supported")
}
// Check if file is supported by mime type
if filetype.IsMIMESupported("image/jpeg") {
fmt.Println("MIME type supported")
} else {
fmt.Println("MIME type not supported")
}
}
File header
package main
import (
"fmt"
"os"
"github.com/h2non/filetype"
)
func main() {
// Open a file descriptor
file, _ := os.Open("movie.mp4")
// We only have to pass the file header = first 261 bytes
head := make([]byte, 261)
file.Read(head)
if filetype.IsImage(head) {
fmt.Println("File is an image")
} else {
fmt.Println("Not an image")
}
}
Add additional file type matchers
package main
import (
"fmt"
"github.com/h2non/filetype"
)
var fooType = filetype.NewType("foo", "foo/foo")
func fooMatcher(buf []byte) bool {
return len(buf) > 1 && buf[0] == 0x01 && buf[1] == 0x02
}
func main() {
// Register the new matcher and its type
filetype.AddMatcher(fooType, fooMatcher)
// Check if the new type is supported by extension
if filetype.IsSupported("foo") {
fmt.Println("New supported type: foo")
}
// Check if the new type is supported by MIME
if filetype.IsMIMESupported("foo/foo") {
fmt.Println("New supported MIME type: foo/foo")
}
// Try to match the file
fooFile := []byte{0x01, 0x02}
kind, _ := filetype.Match(fooFile)
if kind == filetype.Unknown {
fmt.Println("Unknown file type")
} else {
fmt.Printf("File type matched: %s\n", kind.Extension)
}
}
The most recent commit recorded on h2non/filetype was 1 month ago, based on the GitHub push timestamp. The repository has 190 forks — one of the better signals of community interest.
How does h2non/filetype compare to other Backend projects?
h2non/filetype is tracked by TopGit in the Backend category, with 2.3k GitHub stars and written in Go. Browse the Backend topic page on TopGit to compare it against similar projects by stars and activity.
How many stars does h2non/filetype have?
h2non/filetype has 2.3k GitHub stars — refresh the page for the live number, or check github.com/h2non/filetype. TopGit mirrors GitHub's count but does not claim minute-by-minute accuracy.
Is h2non/filetype open source?
Yes — h2non/filetype ships under the MIT license, which makes its source code freely readable (and, depending on license terms, forkable and reusable). Source: github.com/h2non/filetype.
What is h2non/filetype?
h2non/filetype (h2non/filetype) is a Go project on GitHub. From the project's own README: Fast, dependency-free Go package to infer binary file types based on the magic numbers header signature
Where do I read more about h2non/filetype?
This TopGit page is a snapshot — the READ ME tab shows the project's own README content (links stripped, images preserved). The GitHub repository at github.com/h2non/filetype is the definitive source.
Read full README in the tab above.
Still deciding about filetype?
One click hands the question to an AI along with this page — see what it says about filetype.