pepsighan / mime-detective

Detects the mime-type of a file using magic numbers
MIT License
5 stars 2 forks source link

Add a default version 16 magic file #5

Open ManevilleF opened 3 years ago

ManevilleF commented 3 years ago

Using this crate I get this MagicError

Magic(
  MagicError { 
    desc: "File 5.39 supports only version 16 magic files. `/var/folders/y_/nll0fzzn78v4tpzh80x9my4w0000gn/T/.mime_detective_magic.mgc\' is version 14" 
  }
)

using the default MimeDetective::new()

robo9k commented 2 years ago

I've had some issues with the compiled .mgc database files in robo9k/rust-magic#32 as well.

I believe it won't work to dynamically build against one version of libmagic, then use another version at runtime and expect the compiled databases to be compatible. A workaround could be shipping a database in text format and to compile it once on startup. The required magic_compile function is available in the magic crate as Cookie.compile, but I haven't tested this exact use case yet. Another option would be linking libmagic statically, but that use case is not fully supported by the magic-sys crate (yet).

That being said, are you sure you need a custom "default" database? You could just load the default database that comes with the user's libmagic / file installation, see robo9k/rust-magic#22