ruby-filemagic 0.6.3-x86-mingw32 → 0.7.0-x86-mingw32
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/CONTRIBUTING.md +1 -0
- data/ChangeLog +8 -0
- data/README +13 -3
- data/ext/filemagic/extconf.rb +1 -0
- data/ext/filemagic/filemagic.c +40 -16
- data/ext/filemagic/filemagic.h +6 -5
- data/lib/filemagic.rb +21 -6
- data/lib/filemagic/1.9/ruby_filemagic.so +0 -0
- data/lib/filemagic/2.0/ruby_filemagic.so +0 -0
- data/lib/filemagic/2.1/ruby_filemagic.so +0 -0
- data/lib/filemagic/2.2/ruby_filemagic.so +0 -0
- data/lib/filemagic/magic.mgc +0 -0
- data/lib/filemagic/version.rb +2 -2
- data/test/filemagic_test.rb +55 -0
- metadata +13 -8
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 1a94b954dacc17ec6921f126b38779adfbe88021
|
4
|
+
data.tar.gz: 9f69b3625460f35db9a97b884ca0352fc2094c5e
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: df5204089d56d663c99bff278b3b0251ea1224cc1e7f70df90398ea0c123a13970663b9b7ac2325c9579aebc9add0a1610b37631afd0253eb02508dd26477a2d
|
7
|
+
data.tar.gz: c5d97ddcb3ce2b9f68ea57ff835e331febe88af7936e4a0631f99c3f2ae101e3604a0a57911adcd3080d616bbc03116d8cadcf4cbed414b63c8e78483c787898
|
data/CONTRIBUTING.md
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
Please note that this project is in **maintenance mode**. Bug reports and pull requests are welcome, but only [file](http://www.darwinsys.com/file/) **5.11 or higher** is actually supported.
|
data/ChangeLog
CHANGED
@@ -2,6 +2,14 @@
|
|
2
2
|
|
3
3
|
= Revision history for ruby-filemagic
|
4
4
|
|
5
|
+
== 0.7.0 [2015-07-28]
|
6
|
+
|
7
|
+
* Changed FileMagic#io to optionally rewind input afterwards.
|
8
|
+
* New method FileMagic.library_version (+magic_version+).
|
9
|
+
* New method FileMagic#descriptor (+magic_descriptor+).
|
10
|
+
* New method FileMagic#fd.
|
11
|
+
* Added new constants from file 5.23.
|
12
|
+
|
5
13
|
== 0.6.3 [2015-02-06]
|
6
14
|
|
7
15
|
* Fixed build error with Clang (issue #13 by Stan Carver II).
|
data/README
CHANGED
@@ -2,7 +2,7 @@
|
|
2
2
|
|
3
3
|
== VERSION
|
4
4
|
|
5
|
-
This documentation refers to filemagic version 0.
|
5
|
+
This documentation refers to filemagic version 0.7.0
|
6
6
|
|
7
7
|
|
8
8
|
== DESCRIPTION
|
@@ -29,10 +29,11 @@ FileMagic extension module. See also libmagic(3), file(1) and magic(4).
|
|
29
29
|
<tt>check(filename)</tt>:: Checks the validity of entries in the database
|
30
30
|
file passed in as filename
|
31
31
|
<tt>compile(filename)</tt>:: Compiles the database file passed in as filename
|
32
|
+
<tt>load(filename)</tt>:: Loads the database file passed in as filename
|
32
33
|
<tt>close()</tt>:: Closes the magic database and frees any memory
|
33
34
|
allocated
|
34
35
|
|
35
|
-
===
|
36
|
+
=== Synopsis
|
36
37
|
|
37
38
|
require 'filemagic'
|
38
39
|
|
@@ -56,13 +57,22 @@ FileMagic extension module. See also libmagic(3), file(1) and magic(4).
|
|
56
57
|
mime = FileMagic.mime
|
57
58
|
p mime.flags
|
58
59
|
|
60
|
+
=== Environment
|
61
|
+
|
62
|
+
The environment variable +MAGIC+ can be used to set the default magic file name.
|
63
|
+
|
59
64
|
=== Installation
|
60
65
|
|
61
66
|
Install the gem:
|
62
67
|
|
63
68
|
sudo gem install ruby-filemagic
|
64
69
|
|
65
|
-
The file(1) library and headers are required
|
70
|
+
The file(1) library and headers are required:
|
71
|
+
|
72
|
+
Debian/Ubuntu:: +libmagic-dev+
|
73
|
+
Fedora/SuSE:: +file-devel+
|
74
|
+
Gentoo:: +sys-libs/libmagic+
|
75
|
+
OS X:: <tt>brew install libmagic</tt>
|
66
76
|
|
67
77
|
|
68
78
|
== LINKS
|
data/ext/filemagic/extconf.rb
CHANGED
data/ext/filemagic/filemagic.c
CHANGED
@@ -1,5 +1,15 @@
|
|
1
1
|
#include "filemagic.h"
|
2
2
|
|
3
|
+
/* Returns the magic version */
|
4
|
+
static VALUE
|
5
|
+
rb_magic_version(VALUE klass) {
|
6
|
+
char version[8] = "0";
|
7
|
+
#ifdef HAVE_MAGIC_VERSION
|
8
|
+
RB_MAGIC_SET_VERSION(magic_version() / 100, magic_version() % 100)
|
9
|
+
#endif
|
10
|
+
return rb_str_new2(version);
|
11
|
+
}
|
12
|
+
|
3
13
|
/* Returns the magic path */
|
4
14
|
static VALUE
|
5
15
|
rb_magic_getpath(VALUE klass) {
|
@@ -146,12 +156,15 @@ rb_magic_closed_p(VALUE self) {
|
|
146
156
|
return rb_attr_get(self, rb_intern("closed"));
|
147
157
|
}
|
148
158
|
|
149
|
-
/* Return a string describing file */
|
159
|
+
/* Return a string describing the named file */
|
150
160
|
RB_MAGIC_TYPE(file, FILE)
|
151
161
|
|
152
162
|
/* Return a string describing the string buffer */
|
153
163
|
RB_MAGIC_TYPE(buffer, BUFFER)
|
154
164
|
|
165
|
+
/* Return a string describing the file descriptor */
|
166
|
+
RB_MAGIC_TYPE(descriptor, DESCRIPTOR)
|
167
|
+
|
155
168
|
/* Get the flags as array of symbols */
|
156
169
|
static VALUE
|
157
170
|
rb_magic_getflags(VALUE self) {
|
@@ -205,21 +218,23 @@ Init_ruby_filemagic() {
|
|
205
218
|
|
206
219
|
rb_define_const(cFileMagic, "MAGIC_VERSION", rb_str_new2(version));
|
207
220
|
|
208
|
-
rb_define_singleton_method(cFileMagic, "
|
209
|
-
rb_define_singleton_method(cFileMagic, "
|
210
|
-
rb_define_singleton_method(cFileMagic, "
|
211
|
-
|
212
|
-
|
213
|
-
rb_define_method(cFileMagic, "
|
214
|
-
rb_define_method(cFileMagic, "
|
215
|
-
rb_define_method(cFileMagic, "
|
216
|
-
rb_define_method(cFileMagic, "
|
217
|
-
rb_define_method(cFileMagic, "
|
218
|
-
rb_define_method(cFileMagic, "
|
219
|
-
rb_define_method(cFileMagic, "
|
220
|
-
rb_define_method(cFileMagic, "
|
221
|
-
rb_define_method(cFileMagic, "
|
222
|
-
rb_define_method(cFileMagic, "
|
221
|
+
rb_define_singleton_method(cFileMagic, "library_version", rb_magic_version, 0);
|
222
|
+
rb_define_singleton_method(cFileMagic, "path", rb_magic_getpath, 0);
|
223
|
+
rb_define_singleton_method(cFileMagic, "flags", rb_magic_flags, 1);
|
224
|
+
rb_define_singleton_method(cFileMagic, "new", rb_magic_new, -1);
|
225
|
+
|
226
|
+
rb_define_method(cFileMagic, "initialize", rb_magic_init, -1);
|
227
|
+
rb_define_method(cFileMagic, "close", rb_magic_close, 0);
|
228
|
+
rb_define_method(cFileMagic, "closed?", rb_magic_closed_p, 0);
|
229
|
+
rb_define_method(cFileMagic, "file", rb_magic_file, -1);
|
230
|
+
rb_define_method(cFileMagic, "buffer", rb_magic_buffer, -1);
|
231
|
+
rb_define_method(cFileMagic, "descriptor", rb_magic_descriptor, -1);
|
232
|
+
rb_define_method(cFileMagic, "flags", rb_magic_getflags, 0);
|
233
|
+
rb_define_method(cFileMagic, "flags=", rb_magic_setflags, 1);
|
234
|
+
rb_define_method(cFileMagic, "list", rb_magic_list, -1);
|
235
|
+
rb_define_method(cFileMagic, "load", rb_magic_load, -1);
|
236
|
+
rb_define_method(cFileMagic, "check", rb_magic_check, -1);
|
237
|
+
rb_define_method(cFileMagic, "compile", rb_magic_compile, -1);
|
223
238
|
|
224
239
|
rb_alias(cFileMagic, rb_intern("valid?"), rb_intern("check"));
|
225
240
|
|
@@ -267,6 +282,15 @@ Init_ruby_filemagic() {
|
|
267
282
|
#ifdef MAGIC_APPLE
|
268
283
|
rb_define_const(cFileMagic, "MAGIC_APPLE", INT2FIX(MAGIC_APPLE));
|
269
284
|
#endif
|
285
|
+
#ifdef MAGIC_EXTENSION
|
286
|
+
rb_define_const(cFileMagic, "MAGIC_EXTENSION", INT2FIX(MAGIC_EXTENSION));
|
287
|
+
#endif
|
288
|
+
#ifdef MAGIC_COMPRESS_TRANSP
|
289
|
+
rb_define_const(cFileMagic, "MAGIC_COMPRESS_TRANSP", INT2FIX(MAGIC_COMPRESS_TRANSP));
|
290
|
+
#endif
|
291
|
+
#ifdef MAGIC_NODESC
|
292
|
+
rb_define_const(cFileMagic, "MAGIC_NODESC", INT2FIX(MAGIC_NODESC));
|
293
|
+
#endif
|
270
294
|
#ifdef MAGIC_NO_CHECK_COMPRESS
|
271
295
|
rb_define_const(cFileMagic, "MAGIC_NO_CHECK_COMPRESS", INT2FIX(MAGIC_NO_CHECK_COMPRESS));
|
272
296
|
#endif
|
data/ext/filemagic/filemagic.h
CHANGED
@@ -18,19 +18,18 @@
|
|
18
18
|
}\
|
19
19
|
}
|
20
20
|
|
21
|
-
#define RB_MAGIC_TYPE_FILE
|
22
|
-
#define RB_MAGIC_TYPE_BUFFER
|
21
|
+
#define RB_MAGIC_TYPE_FILE magic_file(ms, StringValuePtr(arg))
|
22
|
+
#define RB_MAGIC_TYPE_BUFFER magic_buffer(ms, StringValuePtr(arg), RSTRING_LEN(arg))
|
23
|
+
#define RB_MAGIC_TYPE_DESCRIPTOR magic_descriptor(ms, NUM2INT(arg))
|
23
24
|
|
24
25
|
#define RB_MAGIC_TYPE(what, WHAT) \
|
25
26
|
static VALUE \
|
26
27
|
rb_magic_##what(int argc, VALUE *argv, VALUE self) {\
|
27
28
|
VALUE arg, simple, res;\
|
28
|
-
const char *
|
29
|
+
const char *type;\
|
29
30
|
magic_t ms;\
|
30
31
|
\
|
31
32
|
rb_scan_args(argc, argv, "11", &arg, &simple);\
|
32
|
-
\
|
33
|
-
str = StringValuePtr(arg);\
|
34
33
|
GetMagicSet(self, ms);\
|
35
34
|
\
|
36
35
|
if ((type = RB_MAGIC_TYPE_##WHAT) == NULL) {\
|
@@ -72,6 +71,7 @@ rb_magic_##what(int argc, VALUE *argv, VALUE self) {\
|
|
72
71
|
|
73
72
|
static VALUE cFileMagic, rb_FileMagicError;
|
74
73
|
|
74
|
+
static VALUE rb_magic_version(VALUE);
|
75
75
|
static VALUE rb_magic_getpath(VALUE);
|
76
76
|
static VALUE rb_magic_flags(VALUE, VALUE);
|
77
77
|
|
@@ -84,6 +84,7 @@ static VALUE rb_magic_closed_p(VALUE);
|
|
84
84
|
|
85
85
|
static VALUE rb_magic_file(int, VALUE*, VALUE);
|
86
86
|
static VALUE rb_magic_buffer(int, VALUE*, VALUE);
|
87
|
+
static VALUE rb_magic_descriptor(int, VALUE*, VALUE);
|
87
88
|
|
88
89
|
static VALUE rb_magic_getflags(VALUE);
|
89
90
|
static VALUE rb_magic_setflags(VALUE, VALUE);
|
data/lib/filemagic.rb
CHANGED
@@ -9,6 +9,11 @@ require 'filemagic/version'
|
|
9
9
|
|
10
10
|
class FileMagic
|
11
11
|
|
12
|
+
unless ENV['MAGIC_SILENCE_VERSION_CHECK'] || MAGIC_VERSION == library_version
|
13
|
+
warn "#{self} v#{VERSION}: compiled magic version [#{MAGIC_VERSION}] " <<
|
14
|
+
"does not match with shared library magic version [#{library_version}]"
|
15
|
+
end
|
16
|
+
|
12
17
|
DEFAULT_MAGIC = __FILE__.sub(/\.rb\z/, '/magic.mgc')
|
13
18
|
|
14
19
|
ENV['MAGIC'] ||= DEFAULT_MAGIC unless path
|
@@ -20,15 +25,18 @@ class FileMagic
|
|
20
25
|
:symlink, # Follow symlinks
|
21
26
|
:compress, # Check inside compressed files
|
22
27
|
:devices, # Look at the contents of devices
|
23
|
-
:mime_type, # Return
|
28
|
+
:mime_type, # Return the MIME type
|
24
29
|
:continue, # Return all matches
|
25
30
|
:check, # Print warnings to stderr
|
26
31
|
:preserve_atime, # Restore access time on exit
|
27
|
-
:raw, # Don't
|
32
|
+
:raw, # Don't convert unprintable chars
|
28
33
|
:error, # Handle ENOENT etc as real errors
|
29
|
-
:mime_encoding, # Return
|
34
|
+
:mime_encoding, # Return the MIME encoding
|
30
35
|
:mime, # MAGIC_MIME_TYPE | MAGIC_MIME_ENCODING
|
31
|
-
:apple, # Return the Apple creator
|
36
|
+
:apple, # Return the Apple creator/type
|
37
|
+
:extension, # Return a /-separated list of extensions
|
38
|
+
:compress_transp, # Check inside compressed files but not report compression
|
39
|
+
:nodesc, # MAGIC_EXTENSION | MAGIC_MIME | MAGIC_APPLE
|
32
40
|
:no_check_compress, # Don't check for compressed files
|
33
41
|
:no_check_tar, # Don't check for tar files
|
34
42
|
:no_check_soft, # Don't check magic entries
|
@@ -36,7 +44,7 @@ class FileMagic
|
|
36
44
|
:no_check_elf, # Don't check for elf details
|
37
45
|
:no_check_text, # Don't check for text files
|
38
46
|
:no_check_cdf, # Don't check for cdf files
|
39
|
-
:no_check_tokens, # Don't check
|
47
|
+
:no_check_tokens, # Don't check tokens
|
40
48
|
:no_check_encoding, # Don't check text encodings
|
41
49
|
:no_check_builtin, # No built-in tests; only consult the magic file
|
42
50
|
|
@@ -131,8 +139,15 @@ class FileMagic
|
|
131
139
|
@simplified
|
132
140
|
end
|
133
141
|
|
134
|
-
def io(io, length = 8)
|
142
|
+
def io(io, length = 8, rewind = false)
|
143
|
+
pos = io.pos if rewind
|
135
144
|
buffer(io.read(length))
|
145
|
+
ensure
|
146
|
+
io.pos = pos if pos
|
147
|
+
end
|
148
|
+
|
149
|
+
def fd(fd)
|
150
|
+
descriptor(fd.respond_to?(:fileno) ? fd.fileno : fd)
|
136
151
|
end
|
137
152
|
|
138
153
|
def inspect
|
Binary file
|
Binary file
|
Binary file
|
Binary file
|
data/lib/filemagic/magic.mgc
CHANGED
Binary file
|
data/lib/filemagic/version.rb
CHANGED
data/test/filemagic_test.rb
CHANGED
@@ -59,6 +59,55 @@ magic file from #{FileMagic.path}
|
|
59
59
|
assert_equal('POSIX shell script, ASCII text executable', res)
|
60
60
|
end
|
61
61
|
|
62
|
+
def test_descriptor
|
63
|
+
fm = FileMagic.new(FileMagic::MAGIC_NONE)
|
64
|
+
|
65
|
+
python_script = match_version(
|
66
|
+
0 => 'a python script, ASCII text executable',
|
67
|
+
5.11 => 'Python script, ASCII text executable'
|
68
|
+
)
|
69
|
+
|
70
|
+
fd_for('pyfile') { |fd|
|
71
|
+
res = fm.descriptor(fd)
|
72
|
+
assert_equal(python_script, res)
|
73
|
+
}
|
74
|
+
|
75
|
+
if File.symlink?(path_to('pylink'))
|
76
|
+
fd_for('pylink') { |fd|
|
77
|
+
res = fm.descriptor(fd)
|
78
|
+
assert_equal(python_script, res.strip)
|
79
|
+
}
|
80
|
+
end
|
81
|
+
|
82
|
+
fm.close
|
83
|
+
fm = FileMagic.new(FileMagic::MAGIC_SYMLINK)
|
84
|
+
|
85
|
+
fd_for('pylink') { |fd|
|
86
|
+
res = fm.descriptor(fd)
|
87
|
+
assert_equal(python_script, res)
|
88
|
+
}
|
89
|
+
|
90
|
+
fm.close
|
91
|
+
fm = FileMagic.new(FileMagic::MAGIC_SYMLINK | FileMagic::MAGIC_MIME)
|
92
|
+
|
93
|
+
fd_for('pylink') { |fd|
|
94
|
+
res = fm.descriptor(fd)
|
95
|
+
assert_equal('text/plain; charset=us-ascii', res)
|
96
|
+
}
|
97
|
+
|
98
|
+
fm.close
|
99
|
+
fm = FileMagic.new(FileMagic::MAGIC_COMPRESS)
|
100
|
+
|
101
|
+
fd_for('pyfile-compressed.gz') { |fd|
|
102
|
+
res = fm.descriptor(fd)
|
103
|
+
gzip_compressed = 'gzip compressed data, was "pyfile-compressed"'
|
104
|
+
assert_match(Gem.win_platform? ? /^#{gzip_compressed}/ :
|
105
|
+
/^#{python_script} \(#{gzip_compressed}/, res)
|
106
|
+
}
|
107
|
+
|
108
|
+
fm.close
|
109
|
+
end
|
110
|
+
|
62
111
|
def test_check
|
63
112
|
return if Gem.win_platform?
|
64
113
|
fm = FileMagic.new(FileMagic::MAGIC_NONE)
|
@@ -213,6 +262,12 @@ magic file from #{FileMagic.path}
|
|
213
262
|
File.join(dir, file)
|
214
263
|
end
|
215
264
|
|
265
|
+
def fd_for(file)
|
266
|
+
File.open(path_to(file)) { |f| yield f.fileno }
|
267
|
+
rescue Errno::EBADF => err
|
268
|
+
warn err.to_s
|
269
|
+
end
|
270
|
+
|
216
271
|
def silence_stderr
|
217
272
|
require 'nuggets/io/redirect'
|
218
273
|
$stderr.redirect { yield }
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: ruby-filemagic
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.7.0
|
5
5
|
platform: x86-mingw32
|
6
6
|
authors:
|
7
7
|
- Travis Whitton
|
@@ -9,7 +9,7 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date: 2015-
|
12
|
+
date: 2015-07-28 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: hen
|
@@ -20,7 +20,7 @@ dependencies:
|
|
20
20
|
version: '0.8'
|
21
21
|
- - ">="
|
22
22
|
- !ruby/object:Gem::Version
|
23
|
-
version: 0.8.
|
23
|
+
version: 0.8.2
|
24
24
|
type: :development
|
25
25
|
prerelease: false
|
26
26
|
version_requirements: !ruby/object:Gem::Requirement
|
@@ -30,7 +30,7 @@ dependencies:
|
|
30
30
|
version: '0.8'
|
31
31
|
- - ">="
|
32
32
|
- !ruby/object:Gem::Version
|
33
|
-
version: 0.8.
|
33
|
+
version: 0.8.2
|
34
34
|
- !ruby/object:Gem::Dependency
|
35
35
|
name: rake
|
36
36
|
requirement: !ruby/object:Gem::Requirement
|
@@ -82,6 +82,7 @@ extra_rdoc_files:
|
|
82
82
|
- ChangeLog
|
83
83
|
- ext/filemagic/filemagic.c
|
84
84
|
files:
|
85
|
+
- CONTRIBUTING.md
|
85
86
|
- ChangeLog
|
86
87
|
- README
|
87
88
|
- Rakefile
|
@@ -113,13 +114,17 @@ licenses:
|
|
113
114
|
metadata: {}
|
114
115
|
post_install_message: |2+
|
115
116
|
|
116
|
-
ruby-filemagic-0.
|
117
|
+
ruby-filemagic-0.7.0 [2015-07-28]:
|
117
118
|
|
118
|
-
*
|
119
|
+
* Changed FileMagic#io to optionally rewind input afterwards.
|
120
|
+
* New method FileMagic.library_version (+magic_version+).
|
121
|
+
* New method FileMagic#descriptor (+magic_descriptor+).
|
122
|
+
* New method FileMagic#fd.
|
123
|
+
* Added new constants from file 5.23.
|
119
124
|
|
120
125
|
rdoc_options:
|
121
126
|
- "--title"
|
122
|
-
- ruby-filemagic Application documentation (v0.
|
127
|
+
- ruby-filemagic Application documentation (v0.7.0)
|
123
128
|
- "--charset"
|
124
129
|
- UTF-8
|
125
130
|
- "--line-numbers"
|
@@ -140,7 +145,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
140
145
|
version: '0'
|
141
146
|
requirements: []
|
142
147
|
rubyforge_project:
|
143
|
-
rubygems_version: 2.4.
|
148
|
+
rubygems_version: 2.4.8
|
144
149
|
signing_key:
|
145
150
|
specification_version: 4
|
146
151
|
summary: Ruby bindings to the magic(4) library
|