* MIME type guessing module
@ 2014-12-31 16:36 David Thompson
2015-01-01 0:14 ` Mike Gerwitz
2015-01-02 15:33 ` Thien-Thi Nguyen
0 siblings, 2 replies; 3+ messages in thread
From: David Thompson @ 2014-12-31 16:36 UTC (permalink / raw)
To: guile-devel
Hello Guile hackers,
Recently I've taken to writing simple web servers in Guile. Each time I
write one I wish that core Guile came with a procedure to guess the mime
type of a file. Such a procedure would be very useful when serving
arbitrary static files from disk.
However, I can't figure out the best way to implement it. Here are 3
possible ways of guessing a MIME type:
1) Use a lookup table that maps file extensions to MIME types. This is
the simplest method as it would only test file extensions. Python does
this, see: <https://docs.python.org/2/library/mimetypes.html>
2) Use pipes to read the output of the 'file' utility. The guessing
will be more accurate because 'file' inspects a file's contents to make
better guesses.
3) Use the FFI to call libmagic. Same benefits as above, but better
because we can use the FFI instead of subprocesses and pipes.
2 and 3 both have the disadvantage of requiring an additional
dependency, which seems hard to justify for such a minor feature.
I wrote a simple static file server (inspired by Python's
SimpleHTTPServer) that I would like to contribute once this blocker is
resolved.
Thoughts? Would this be useful at all?
Thanks,
--
David Thompson
Web Developer - Free Software Foundation - http://fsf.org
GPG Key: 0FF1D807
Support the FSF: https://fsf.org/donate
^ permalink raw reply [flat|nested] 3+ messages in thread
* Re: MIME type guessing module
2014-12-31 16:36 MIME type guessing module David Thompson
@ 2015-01-01 0:14 ` Mike Gerwitz
2015-01-02 15:33 ` Thien-Thi Nguyen
1 sibling, 0 replies; 3+ messages in thread
From: Mike Gerwitz @ 2015-01-01 0:14 UTC (permalink / raw)
To: David Thompson; +Cc: guile-devel
-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1
On Wed, Dec 31, 2014 at 11:36:22 -0500, David Thompson wrote:
> Recently I've taken to writing simple web servers in Guile. Each time I
> write one I wish that core Guile came with a procedure to guess the mime
> type of a file. Such a procedure would be very useful when serving
> arbitrary static files from disk.
I'm paused on a guile-mime project that reads a XDG Shared MIME-Info
globs2 database[0]:
https://gitorious.org/guile-mime
I was planning on continuing it's development shortly. Do you agree
with that approach?
If you want to cooperate on an effort, that's fine with me.
(The database is distributed with most GNU/Linux distributions and can
be referenced with the `xdg*` commands on the system.)
[0]: http://standards.freedesktop.org/shared-mime-info-spec/shared-mime-info-spec-latest.html
- --
Mike Gerwitz
Free Software Hacker | GNU Maintainer
http://mikegerwitz.com
FSF Member #5804 | GPG Key ID: 0x8EE30EAB
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1
iQIcBAEBAgAGBQJUpJFMAAoJEPIruBWO4w6rAIgP/Aw0gMEWr6Zr4uLArBXR3Ove
ixrZ1Bfgw1Mef7q7p9qwVX45NSyKt3uZs5HPsCRwQ3tALdLLZTPZw1YR7WhAXbBl
gq109+38iY3yN8J0wqwAS1EiNgp98EYiKKP7OwuabyfRRTkEQxKyWKnxw8MRsQgz
E6lC5JyMr0J8PdE8kxVBQFq4NDsjqRSlMEA8krKs68KywpbtbJEjGvlZkdOv+kWP
fu/fyI0p2hMjhKuCd5u74sIM1LdBgnzyWmRhrtDniC/fgXRgBaehnAaPZUIAwE2p
qWF7hVN8ngnumhO4h4+SjaBDIuSmRpQV9IoKROplhhCwqByflqrZdaOZnPINcb5e
sc11wha/B2Gfv5rvq/eTGHZoPeRY6IV4TeCWUHwSPlDq7IPyw5j8xRtTtuvEKDl2
xZaLJkcJq7VJv9Qv0I7/otDFAN/MPf8wO0N4ODci2SsBs4bjjouZNyyB0w5V8QDl
7/8MGVYcnzqRdP7raarQMrCJFlOUU7OIUv0odlcHd3vnvqM/k2RMJj7pkKpe9EUM
hcCkhmT0pT1ZzTkeGpuikCW7hPe50h0di00kNgUjjzZptaYX9FF3TNWBSMdBBtEM
Viybrf0YfWuLXNP/4oQbtRQ0F7oYec/K1eVustyrtLv0GN43Ch/lVQdl+SYvWkCJ
KnyiIxNLnxsh9xMK8j5i
=jP6t
-----END PGP SIGNATURE-----
^ permalink raw reply [flat|nested] 3+ messages in thread
* Re: MIME type guessing module
2014-12-31 16:36 MIME type guessing module David Thompson
2015-01-01 0:14 ` Mike Gerwitz
@ 2015-01-02 15:33 ` Thien-Thi Nguyen
1 sibling, 0 replies; 3+ messages in thread
From: Thien-Thi Nguyen @ 2015-01-02 15:33 UTC (permalink / raw)
To: guile-devel
[-- Attachment #1: Type: text/plain, Size: 757 bytes --]
() David Thompson <dthompson2@worcester.edu>
() Wed, 31 Dec 2014 11:36:22 -0500
Thoughts? Would this be useful at all?
Well, if you use it, then it's useful, yes? :-D
There's always room for more implementations.
Check out libextractor:
http://www.gnu.org/software/libextractor/
See also "ttn-do magic", which is a pure-Scheme solution:
http://www.gnuvola.org/software/ttn-do/ttn-do.html.gz#magic
The database is also "Schemey" -- sexps produced from parsing
~/.magic or other magic(5) databases.
--
Thien-Thi Nguyen
GPG key: 4C807502
(if you're human and you know it)
read my lisp: (responsep (questions 'technical)
(not (via 'mailing-list)))
=> nil
[-- Attachment #2: signature.asc --]
[-- Type: application/pgp-signature, Size: 197 bytes --]
^ permalink raw reply [flat|nested] 3+ messages in thread
end of thread, other threads:[~2015-01-02 15:33 UTC | newest]
Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2014-12-31 16:36 MIME type guessing module David Thompson
2015-01-01 0:14 ` Mike Gerwitz
2015-01-02 15:33 ` Thien-Thi Nguyen
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).