mime 0.1.2

Shared MIME-info Database specification implementation


To use this package, run the following command in your project's root directory:

Manual usage
Put the following dependency into your project's dependences section:


This package provides sub packages which can be used individually:

mime:mimecache - A minimal D application.

mime:mimedatabase - A minimal D application.

mime:magic - A minimal D application.

Mime

Shared MIME-info database specification implementation in D programming language.

Generating documentation

Ddoc:

dub build --build=docs

Ddox:

dub build --build=ddox

Examples

MimeCache

Run to detect mime type of README.md or other file using mime.cache file:

dub run mime:mimecache -- /usr/share/mime/mime.cache README.md

MimeDatabase

Print short information on all found MIME types.

dub run mime:mimedatabase -- --printDatabase=true

Run to detect mime types of files.

dub run mime:mimedatabase -- --file=README.md --file=source --file=.gitignore --file=lib/libmime.a

TODO

  1. Implement MIME type detection from file contents (via magic).
  2. Read MIME types from mime/packages sources (need xml library).
  3. Determine MIME type by XMLnamespace if document is xml (need streaming xml library).
  4. Implement merging of many files into one database (user defined one from .local/share/mime should be used before system-wide defined /usr/share/mime).
  5. Allow to create MIME types (need xml library) and call update-mime-database.

Interface and implementation discussion

Which interfaces library should provide? The obvious way is to make MimeType and MimeDatabase classes. But there're at least 3 ways to read mime database:

  1. From mime.cache. It lacks additional information (like comments, acronyms and additional fields), optimized for lookup, but not for storing MIME types as separate objects).
  2. From various generated files like globs, icons, magic, etc (not optimized, also lacks information, but easy to read).
  3. From mime/packages sources. It's straight-forward and the most complete (in sense it does not lose any information) way, but requires XML parsing.

All can be implemented as different MimeDatabase classes inherited the same interface.

What about thread safety?

MimeType matters:

  1. Should MimeType be class or struct?
  2. Should MimeType be independent from database it was read from?
  3. Should MimeType always preserve all information if it was loaded from xml source?

Should MimeDatabse detect MIME types for non-regular files? (inode/directory, etc.) Should MimeDatabse distinguish between text and binary data (text/plain vs application/octet-stream) when could not determine MIME type?

Authors:
  • Roman Chistokhodov
Sub packages:
mime:mimecache, mime:mimedatabase, mime:magic
Dependencies:
none
Versions:
0.5.2 2020-Sep-29
0.5.1 2018-Oct-20
0.5.0 2018-Oct-10
0.4.3 2018-May-04
0.4.2 2016-Sep-26
Show all 17 versions
Download Stats:
  • 1 downloads today

  • 1 downloads this week

  • 1 downloads this month

  • 346 downloads total

Score:
0.9
Short URL:
mime.dub.pm