-
Notifications
You must be signed in to change notification settings - Fork 34
/
README
129 lines (87 loc) · 3.34 KB
/
README
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
= FileMagic Library Binding
== VERSION
This documentation refers to filemagic version 0.7.3
== DESCRIPTION
FileMagic extension module. See also libmagic(3), file(1) and magic(4).
=== Constants
<tt>MAGIC_NONE</tt>:: No flags
<tt>MAGIC_DEBUG</tt>:: Turn on debugging
<tt>MAGIC_SYMLINK</tt>:: Follow symlinks
<tt>MAGIC_COMPRESS</tt>:: Check inside compressed files
<tt>MAGIC_DEVICES</tt>:: Look at the contents of devices
<tt>MAGIC_MIME</tt>:: Return a mime string
<tt>MAGIC_CONTINUE</tt>:: Return all matches, not just the first
<tt>MAGIC_CHECK</tt>:: Print warnings to stderr
=== Methods
<tt>file(filename)</tt>:: Returns a textual description of the contents
of the filename argument
<tt>buffer(string)</tt>:: Returns a textual description of the contents
of the string argument
<tt>check(filename)</tt>:: Checks the validity of entries in the database
file passed in as filename
<tt>compile(filename)</tt>:: Compiles the database file passed in as filename
<tt>load(filename)</tt>:: Loads the database file passed in as filename
<tt>close()</tt>:: Closes the magic database and frees any memory
allocated
=== Synopsis
require 'filemagic'
p FileMagic::VERSION
# => "0.7.3"
p FileMagic::MAGIC_VERSION
# => "5.39"
p FileMagic.new.flags
# => []
FileMagic.open(:mime) { |fm|
p fm.flags
# => [:mime_type, :mime_encoding]
p fm.file(__FILE__)
# => "text/plain; charset=us-ascii"
p fm.file(__FILE__, true)
# => "text/plain"
fm.flags = [:raw, :continue]
p fm.flags
# => [:continue, :raw]
}
fm = FileMagic.new
p fm.flags
# => []
mime = FileMagic.mime
p mime.flags
# => [:mime_type, :mime_encoding]
=== Environment
The environment variable +MAGIC+ can be used to set the default magic file name.
=== Installation
Install the gem:
sudo gem install ruby-filemagic
The file(1) library and headers are required:
Debian/Ubuntu:: +libmagic-dev+
Fedora/SuSE:: +file-devel+
Alpine:: <tt>libmagic file file-dev</tt>
Gentoo:: +sys-libs/libmagic+
OS X:: <tt>brew install libmagic</tt>
=== Build native extension
rake docker:gem:native
Requires Docker[https://docker.com] to be installed.
== LINKS
Homepage:: https://www.darwinsys.com/file/
Documentation:: https://blackwinter.github.io/ruby-filemagic
Source code:: https://github.com/blackwinter/ruby-filemagic
RubyGem:: https://rubygems.org/gems/ruby-filemagic
Travis CI:: https://travis-ci.org/blackwinter/ruby-filemagic
== AUTHORS
* Travis Whitton <mailto:[email protected]> (Original author)
* Jens Wille <mailto:[email protected]>
== CREDITS
* Martin Carpenter <mailto:[email protected]> for Ruby 1.9.2 compatibility
and other improvements.
* Pavel Lobashov (@ShockwaveNN) for Dockerfile to build cross-compiled Windows
extension (pull request #26).
== COPYING
The filemagic extension library is copywrited free software by Travis Whitton
<[email protected]>. You can redistribute it under the terms specified in
the COPYING file of the Ruby distribution.
== WARRANTY
THIS SOFTWARE IS PROVIDED "AS IS" AND WITHOUT ANY EXPRESS OR
IMPLIED WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED
WARRANTIES OF MERCHANTIBILITY AND FITNESS FOR A PARTICULAR
PURPOSE.