h2non/filetype được TopGit xếp vào nhóm dự án backend, với 2.3k sao trên GitHub, viết chủ yếu bằng Go. Fast, dependency-free Go package to infer binary file types based on the magic numbers header signature
Tóm tắt dựng từ metadata GitHub của chính dự án — chưa có bài review TopGit. Trang sẽ tự động cập nhật khi bài review đầy đủ được xuất bản.
VÌ SAO CHƯA CÓ REVIEW
TopGit viết bài đầy đủ cho repo có nhiều sao nhất và được yêu cầu nhiều nhất. Trang này là snapshot trong thời gian chờ — xem README gốc ở tab READ ME.
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)
}
}
Trang TopGit này là một snapshot — tab "Readme" hiển thị nguyên văn README của repo (đã bỏ link, giữ ảnh). Repo GitHub ở github.com/h2non/filetype là nguồn chính thức.
h2non/filetype có bao nhiêu sao?
h2non/filetype có 2.3k sao GitHub — tải lại trang để xem số mới nhất, hoặc xem trực tiếp github.com/h2non/filetype. TopGit phản chiếu số sao của GitHub nhưng không cam kết đến từng phút.
h2non/filetype có phải mã nguồn mở không?
Có — h2non/filetype phát hành theo license MIT, nghĩa là mã nguồn mở để đọc, fork và (tùy license) tái sử dụng. Mã: github.com/h2non/filetype.
h2non/filetype còn đang phát triển không?
Commit gần nhất trên h2non/filetype là 4 tháng trước (theo timestamp GitHub). Repo có 194 fork — một chỉ báo về mức độ quan tâm của cộng đồng.
h2non/filetype là gì?
h2non/filetype (h2non/filetype) là dự án Go trên GitHub. Theo mô tả gốc: Fast, dependency-free Go package to infer binary file types based on the magic numbers header signature
h2non/filetype so với các dự án Backend khác thế nào?
h2non/filetype được TopGit xếp vào nhóm Backend, với 2.3k sao GitHub và viết bằng Go. Xem trang chủ đề Backend trên TopGit để so sánh với các dự án tương tự theo số sao và mức độ hoạt động.
Đọc đầy đủ README ở tab phía trên.
Vẫn đang phân vân về filetype?
Một cú bấm sẽ gửi câu hỏi kèm trang này cho AI — xem AI nói gì về filetype.