source: project/wiki/eggref/4/magic @ 33385

Last change on this file since 33385 was 33385, checked in by evhan, 3 years ago

egg-locations: Migrate my eggs from bitbucket.org to foldling.org

File size: 2.4 KB
Line 
1[[tags: egg]]
2
3== magic
4
5[[toc:]]
6
7=== Description
8
9libmagic bindings.
10
11Two modules are included, {{libmagic}} and {{magic}}:
12
13* {{libmagic}} is a one-to-one binding to {{libmagic.h}}, used exactly
14  like the C library.
15* {{magic}} is a high-level wrapper, providing one procedure called
16  {{identify}}.
17
18The following documentation applies to the {{magic}} module.
19
20The source for this egg is available
21[[http://git.foldling.org/chicken-magic.git|here]].
22
23=== API
24
25One procedure is provided, {{identify}}, that tries to do what you mean
26based on the type of its argument. Whenever libmagic returns an error,
27an exception of type {{(exn magic)}} is raised.
28
29Note that this module loads libmagic's magic numbers database as soon as
30it's {{require}}d (a.k.a. {{use}}d). If you're not OK with this, use the
31low-level module.
32
33<procedure>(identify [object [flags]]) => string</procedure>
34
35{{identify}} returns a textual description of the file indicated by
36{{object}}, or the contents of {{(current-input-port)}} if no {{object}}
37is specified.
38
39If {{object}} is given, it may be any of the following types, with
40{{identify}} returning a description of:
41
42* {{blob}}: the contents of the blob.
43* {{string}}: the contents of the file indicated by the given filename.
44* {{integer}}: the contents of that file descriptor.
45* {{input-port}}: the contents of the port. This port must be
46  backed by a file descriptor; if not, an error of type {{(exn type)}}
47  will be raised.
48
49If {{flags}} is given, it should be a symbol or list of symbols
50indicating the type of description to return. These correspond to the
51{{MAGIC_*}} constants in {{magic.h}}, and can be any combination of the
52following (though not all combinations make sense):
53
54* {{apple}}
55* {{compress}}
56* {{device}}
57* {{mime}}
58* {{mime-encoding encoding}}
59* {{mime-type type}}
60* {{no-apptype}}
61* {{no-cdf}}
62* {{no-compress}}
63* {{no-elf}}
64* {{no-encoding}}
65* {{no-soft}}
66* {{no-tar}}
67* {{no-text}}
68* {{no-tokens}}
69* {{none}}
70* {{preserve-atime}}
71* {{raw}}
72* {{symlink}}
73
74For example:
75
76<enscript highlight="scheme">
77(identify "/usr/include/magic.h") ; => "C source, ASCII text"
78(identify "/usr/include/magic.h" 'mime) ; => "text/x-c; charset=us-ascii"
79(identify "/usr/include/magic.h" '(preserve-atime no-text)) ; => "data"
80</enscript>
81
82An unrecognized flag will raise an exception of type {{(exn magic)}}.
83
84=== Author
85
86[[/users/evan-hanson|Evan Hanson]]
87
88=== License
89
90Copyright (c) 2013, 3-Clause BSD.
Note: See TracBrowser for help on using the repository browser.