~taiju/guile-mime

MIME Types utility for Guile
Modify the source definition.
Fix to keep text file README.
Bump up version number.

clone

read-only
https://git.sr.ht/~taiju/guile-mime
read/write
git@git.sr.ht:~taiju/guile-mime

You can also use your local clone with git send-email.

#What is Guile-MIME?

Guile-MIME is a MIME types utility for Guile, providing utility functions such as ext->type, type->exts, file->type.

#Why did you need Guile-MIME?

http.server of Python or Rack of Ruby has MIME types database that doesn't depend on other external resources.

I wanted need those that unnecessary depend on external resources and easily use and modify the database why I created this.

SEE ALSO:

#Where is the MIME types data comes from?

Original data is the mime-db project has. SEE: https://github.com/jshttp/mime-db

MIME types data is removed if they don't have extensions definition and converted from JSON to association list of Scheme. Also, if there are multiple MIME types candidates against an extension, keep one and delete the rest. The MIME type to keep is determined by the author's preference. So, please modify those if you want to keep another candidate.

SEE: conflict-ext-type-map in (mime db)

This logic can be found "scripts/guile-mime-db.in".

#SYNOPSYS

$ guile
GNU Guile 3.0.8
Copyright (C) 1995-2021 Free Software Foundation, Inc.

Guile comes with ABSOLUTELY NO WARRANTY; for details type `,show w'.
This program is free software, and you are welcome to redistribute it
under certain conditions; type `,show c' for details.

Enter `,help' for help.
scheme@(guile-user)> ,use (mime)
scheme@(guile-user)> (ext->type "htm")
$1 = "text/html"
scheme@(guile-user)> (ext->type "html")
$2 = "text/html"
scheme@(guile-user)> (ext->type "unknown")
$3 = #f
scheme@(guile-user)> (type->exts "text/html")
$4 = ("html" "htm" "shtml")
scheme@(guile-user)> (type->exts "text/css")
$5 = ("css")
scheme@(guile-user)> (type->exts "unknown")
$6 = #f
scheme@(guile-user)> (file->type "index.html")
$7 = "text/html"
scheme@(guile-user)> (file->type "/assets/stylesheets/style.css")
$8 = "text/css"
scheme@(guile-user)> (file->type "https://example.com/js/script.js")
$9 = "application/javascript"
scheme@(guile-user)> (file->type "unknown")
$10 = #f

#INSTALLATION

$ cd /path/to/here
$ guix package -f guix.scm

#Procedures

#ext->type

  • interface
    • (ext->type extension)
  • return value
    • MIME type (string)
  • module
    • (mime)
  • example
    • (ext->type "htm")

#type->exts

  • interface
    • (type->exts mime-type)
  • return value
    • Extension list (string list)
  • module
    • (mime)
  • example
    • (type->exts "text/html")

#file->type

  • interface
    • (file->type filename)
  • return value
    • MIME type (string)
  • module
    • (mime)
  • example
    • (file->type "index.html")
    • (file->type "/assets/stylesheets/style.css")
    • (file->type "https://example.com/js/script.js")

#Tips

Here are some tips for using the library.

#How to modify databases?

It doesn't provide a dedicated way yet that modifies databases.

However, feel free to change them and use them as shown below.

(use-modules (mime))

(set! (@ (mime db) ext-type-db)
      (cons '("html" . "text/x-my-special-html") (@ (mime db) ext-type-db)))

(set! (@ (mime db) type-exts-db)
      (cons '("text/x-my-special-html" "html" "htm" "shtml") (@ (mime db) type-exts-db)))

(display (ext->type "html"))
(newline)
;; => "text/x-my-special-html"

(display (type->exts "text/x-my-special-html"))
(newline)
;; => ("html" "htm" "shtml")

#How do I contact you?

If you have any questions and feature requests, submit patches, please send them to the public mailing list ~taiju/Guile-MIME@lists.sr.ht.