zRedShift / mimemagic

Powerful and versatile MIME sniffing package using pre-compiled glob patterns, magic number signatures, XML document namespaces, and tree magic for mounted volumes, generated from the XDG shared-mime-info database.
GNU General Public License v2.0
99 stars 10 forks source link

why detect json file to plainText #2

Closed MoonJustry closed 3 years ago

MoonJustry commented 5 years ago

json data like

{
    "key":"value"
}

but Match result is text/plain

zRedShift commented 5 years ago

There is no magic file signature for JSON files in the XDG shared-mime-info database, it only matches by glob (*.json). Since JSON isn't a regular language, it can't be trivially ascertained using byte-by-byte comparisons and searches. Here's how file/libmagic does it. If you'd like to work on porting that code to Go, mimemagic could be trivially extended to implement the same functionality.