ruby-filemagic 0.6.3 → 0.7.3

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
- SHA1:
3
- metadata.gz: c40ff0bb38f52109a4cd1ae3c14307b19e78a945
4
- data.tar.gz: ba3119c345c3a1a64624422032a8a7cad026aee9
2
+ SHA256:
3
+ metadata.gz: 072a4b2682df79e50b62c7cf1c0b42db262bac212f90ec741fdf5b82b89a661f
4
+ data.tar.gz: ccce9e4086fd53a704ff20d5ed0fdeeec384f21e346ac0e228505f8802337b02
5
5
  SHA512:
6
- metadata.gz: b8f010daf0bae4d574340a8d1d55a564e21532374188e3afe117f074c942a47f6e4ce216debe1ae76b90a8d5c00c001734a2d1775967c7f88e110554a083b9b0
7
- data.tar.gz: b362c2a4ea725dba072439238bec60c6d414e9784c128f48bef884121a2dff448ebe8d3cd6df343eabdbfa1d6688a71f311a7252f49018c2d0e9346a537e657e
6
+ metadata.gz: 42f6d02a666eefcfa9647cabe589ade5b7b2bae7e37cf9613b20cfe5190ab722543659028bf601b3b196a58c911596eed30cc9413544f3cdeaa5b335aa09c576
7
+ data.tar.gz: acf53f89c934e944917b80cfa62150da43b6b430bf4bce8798ad17b93dc54546a5092c42bdd0facf8eb35a0e12c56415a3b48409075e6262aadc93dcaae77be9
data/CONTRIBUTING.md ADDED
@@ -0,0 +1 @@
1
+ Please note that this project is **no longer maintained**. I'm happy to hand over ownership to anyone who shows serious interest.
data/ChangeLog CHANGED
@@ -2,6 +2,29 @@
2
2
 
3
3
  = Revision history for ruby-filemagic
4
4
 
5
+ == 0.7.3 [2022-01-07]
6
+
7
+ * Dockerfile to build native extension (pull request #26 by Pavel Lobashov).
8
+ * Include paths for ARM-based Apple Macs (Apple Silicon) (pull request #35 by
9
+ @545ch4).
10
+
11
+ == 0.7.2 [2017-07-02]
12
+
13
+ * Fix segfault on <tt>buffer(nil)</tt> when compiled with GCC (pull request
14
+ #24 by Yuya Tanaka).
15
+
16
+ == 0.7.1 [2015-10-27]
17
+
18
+ * List default lib and header directories (pull request #18 by Adam Wróbel).
19
+
20
+ == 0.7.0 [2015-07-28]
21
+
22
+ * Changed FileMagic#io to optionally rewind input afterwards.
23
+ * New method FileMagic.library_version (+magic_version+).
24
+ * New method FileMagic#descriptor (+magic_descriptor+).
25
+ * New method FileMagic#fd.
26
+ * Added new constants from file 5.23.
27
+
5
28
  == 0.6.3 [2015-02-06]
6
29
 
7
30
  * Fixed build error with Clang (issue #13 by Stan Carver II).
data/Dockerfile ADDED
@@ -0,0 +1,37 @@
1
+ FROM ruby:2.4
2
+
3
+ RUN apt-get update && apt-get install -y mingw-w64 && gem install rake-compiler
4
+ ENV HOST_ARCH i686-w64-mingw32
5
+
6
+ ENV GNURX_VERSION 2.5.1
7
+ ENV GNURX_SOURCE /mingw-libgnurx-$GNURX_VERSION
8
+ RUN curl https://vorboss.dl.sourceforge.net/project/mingw/Other/UserContributed/regex/mingw-regex-$GNURX_VERSION/mingw-libgnurx-$GNURX_VERSION-src.tar.gz | \
9
+ tar xzvf - && \
10
+ cd $GNURX_SOURCE && \
11
+ ./configure --host=$HOST_ARCH --enable-static --disable-shared && \
12
+ make
13
+
14
+ ENV MAGIC_VERSION 5.31
15
+ ENV MAGIC_SOURCE /file-$MAGIC_VERSION
16
+ RUN curl ftp://ftp.astron.com/pub/file/file-$MAGIC_VERSION.tar.gz | \
17
+ tar xzvf - && \
18
+ cd $MAGIC_SOURCE && \
19
+ ./configure --disable-silent-rules --enable-fsect-man5 && \
20
+ make && \
21
+ make clean && \
22
+ LDFLAGS=-L$GNURX_SOURCE CFLAGS=-I$GNURX_SOURCE ./configure --disable-silent-rules --enable-fsect-man5 --host=$HOST_ARCH && \
23
+ make || true
24
+
25
+ ENV CROSS_RUBIES 2.3.4 2.4.1
26
+ RUN for i in $CROSS_RUBIES; do rake-compiler cross-ruby VERSION=$i; done
27
+
28
+ ENV APP_SOURCE /ruby-filemagic
29
+ RUN mkdir $APP_SOURCE
30
+ WORKDIR $APP_SOURCE
31
+
32
+ RUN echo "source 'https://rubygems.org'\ngemspec\n" > Gemfile
33
+ COPY *.gemspec .
34
+ RUN bundle install
35
+
36
+ COPY . .
37
+ ENTRYPOINT rake gem:native WITH_CROSS_GNURX=$GNURX_SOURCE WITH_CROSS_MAGIC=$MAGIC_SOURCE
data/README CHANGED
@@ -2,7 +2,7 @@
2
2
 
3
3
  == VERSION
4
4
 
5
- This documentation refers to filemagic version 0.6.3
5
+ This documentation refers to filemagic version 0.7.3
6
6
 
7
7
 
8
8
  == DESCRIPTION
@@ -29,32 +29,46 @@ 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
- === Synospis
36
+ === Synopsis
36
37
 
37
38
  require 'filemagic'
38
39
 
39
40
  p FileMagic::VERSION
41
+ # => "0.7.3"
40
42
  p FileMagic::MAGIC_VERSION
43
+ # => "5.39"
41
44
 
42
45
  p FileMagic.new.flags
46
+ # => []
43
47
 
44
48
  FileMagic.open(:mime) { |fm|
45
49
  p fm.flags
50
+ # => [:mime_type, :mime_encoding]
46
51
  p fm.file(__FILE__)
52
+ # => "text/plain; charset=us-ascii"
47
53
  p fm.file(__FILE__, true)
54
+ # => "text/plain"
48
55
 
49
56
  fm.flags = [:raw, :continue]
50
57
  p fm.flags
58
+ # => [:continue, :raw]
51
59
  }
52
60
 
53
61
  fm = FileMagic.new
54
62
  p fm.flags
63
+ # => []
55
64
 
56
65
  mime = FileMagic.mime
57
66
  p mime.flags
67
+ # => [:mime_type, :mime_encoding]
68
+
69
+ === Environment
70
+
71
+ The environment variable +MAGIC+ can be used to set the default magic file name.
58
72
 
59
73
  === Installation
60
74
 
@@ -62,13 +76,23 @@ Install the gem:
62
76
 
63
77
  sudo gem install ruby-filemagic
64
78
 
65
- The file(1) library and headers are required.
79
+ The file(1) library and headers are required:
80
+
81
+ Debian/Ubuntu:: +libmagic-dev+
82
+ Fedora/SuSE:: +file-devel+
83
+ Gentoo:: +sys-libs/libmagic+
84
+ OS X:: <tt>brew install libmagic</tt>
66
85
 
86
+ === Build native extension
87
+
88
+ rake docker:gem:native
89
+
90
+ Requires Docker[https://docker.com] to be installed.
67
91
 
68
92
  == LINKS
69
93
 
70
- Homepage:: http://www.darwinsys.com/file/
71
- Documentation:: https://blackwinter.github.com/ruby-filemagic
94
+ Homepage:: https://www.darwinsys.com/file/
95
+ Documentation:: https://blackwinter.github.io/ruby-filemagic
72
96
  Source code:: https://github.com/blackwinter/ruby-filemagic
73
97
  RubyGem:: https://rubygems.org/gems/ruby-filemagic
74
98
  Travis CI:: https://travis-ci.org/blackwinter/ruby-filemagic
@@ -85,6 +109,9 @@ Travis CI:: https://travis-ci.org/blackwinter/ruby-filemagic
85
109
  * Martin Carpenter <mailto:mcarpenter@free.fr> for Ruby 1.9.2 compatibility
86
110
  and other improvements.
87
111
 
112
+ * Pavel Lobashov (@ShockwaveNN) for Dockerfile to build cross-compiled Windows
113
+ extension (pull request #26).
114
+
88
115
 
89
116
  == COPYING
90
117
 
data/Rakefile CHANGED
@@ -32,3 +32,20 @@ begin
32
32
  rescue LoadError => err
33
33
  warn "Please install the `hen' gem. (#{err})"
34
34
  end
35
+
36
+ namespace :docker do
37
+
38
+ name = "ruby-filemagic-gem-native:#{FileMagic::VERSION}"
39
+
40
+ task :build do
41
+ sh *%W[docker build -t #{name} .]
42
+ end
43
+
44
+ task :run do
45
+ sh *%W[docker run -it --rm -v #{Dir.pwd}/pkg:/ruby-filemagic/pkg #{name}]
46
+ end
47
+
48
+ desc "Build native gems using docker image #{name}"
49
+ task 'gem:native' => %w[build run]
50
+
51
+ end
@@ -1,14 +1,29 @@
1
1
  require 'mkmf'
2
2
 
3
+ HEADER_DIRS = [
4
+ '/opt/local/include', # MacPorts
5
+ '/usr/local/include', # compiled from source and Homebrew
6
+ '/opt/homebrew/include', # compiled from source and Homebrew (ARM based Macs)
7
+ '/usr/include', # system
8
+ ]
9
+
10
+ LIB_DIRS = [
11
+ '/opt/local/lib', # MacPorts
12
+ '/usr/local/lib', # compiled from source and Homebrew
13
+ '/opt/homebrew/lib', # compiled from source and Homebrew (ARM based Macs)
14
+ '/usr/lib', # system
15
+ ]
16
+
3
17
  $CFLAGS << ' -Wall' if ENV['WALL']
4
18
  $LDFLAGS << ' -static-libgcc' if RUBY_PLATFORM =~ /cygwin|mingw|mswin/
5
19
 
6
- dir_config('magic')
7
- dir_config('gnurx')
20
+ dir_config('magic', HEADER_DIRS, LIB_DIRS)
21
+ dir_config('gnurx', HEADER_DIRS, LIB_DIRS)
8
22
 
9
23
  have_library('gnurx')
10
24
 
11
25
  if have_library('magic', 'magic_open') && have_header('magic.h')
26
+ have_func('magic_version')
12
27
  have_header('file/patchlevel.h')
13
28
  create_makefile('filemagic/ruby_filemagic')
14
29
  else
@@ -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) {
@@ -102,6 +112,7 @@ rb_magic_init(int argc, VALUE *argv, VALUE self) {
102
112
 
103
113
  rb_iv_set(self, "iflags", flags);
104
114
  rb_iv_set(self, "closed", Qfalse);
115
+ rb_iv_set(self, "@simplified", Qfalse);
105
116
 
106
117
  keys = rb_funcall(options, rb_intern("keys"), 0);
107
118
 
@@ -146,12 +157,15 @@ rb_magic_closed_p(VALUE self) {
146
157
  return rb_attr_get(self, rb_intern("closed"));
147
158
  }
148
159
 
149
- /* Return a string describing file */
160
+ /* Return a string describing the named file */
150
161
  RB_MAGIC_TYPE(file, FILE)
151
162
 
152
163
  /* Return a string describing the string buffer */
153
164
  RB_MAGIC_TYPE(buffer, BUFFER)
154
165
 
166
+ /* Return a string describing the file descriptor */
167
+ RB_MAGIC_TYPE(descriptor, DESCRIPTOR)
168
+
155
169
  /* Get the flags as array of symbols */
156
170
  static VALUE
157
171
  rb_magic_getflags(VALUE self) {
@@ -205,21 +219,23 @@ Init_ruby_filemagic() {
205
219
 
206
220
  rb_define_const(cFileMagic, "MAGIC_VERSION", rb_str_new2(version));
207
221
 
208
- rb_define_singleton_method(cFileMagic, "path", rb_magic_getpath, 0);
209
- rb_define_singleton_method(cFileMagic, "flags", rb_magic_flags, 1);
210
- rb_define_singleton_method(cFileMagic, "new", rb_magic_new, -1);
211
-
212
- rb_define_method(cFileMagic, "initialize", rb_magic_init, -1);
213
- rb_define_method(cFileMagic, "close", rb_magic_close, 0);
214
- rb_define_method(cFileMagic, "closed?", rb_magic_closed_p, 0);
215
- rb_define_method(cFileMagic, "file", rb_magic_file, -1);
216
- rb_define_method(cFileMagic, "buffer", rb_magic_buffer, -1);
217
- rb_define_method(cFileMagic, "flags", rb_magic_getflags, 0);
218
- rb_define_method(cFileMagic, "flags=", rb_magic_setflags, 1);
219
- rb_define_method(cFileMagic, "list", rb_magic_list, -1);
220
- rb_define_method(cFileMagic, "load", rb_magic_load, -1);
221
- rb_define_method(cFileMagic, "check", rb_magic_check, -1);
222
- rb_define_method(cFileMagic, "compile", rb_magic_compile, -1);
222
+ rb_define_singleton_method(cFileMagic, "library_version", rb_magic_version, 0);
223
+ rb_define_singleton_method(cFileMagic, "path", rb_magic_getpath, 0);
224
+ rb_define_singleton_method(cFileMagic, "flags", rb_magic_flags, 1);
225
+ rb_define_singleton_method(cFileMagic, "new", rb_magic_new, -1);
226
+
227
+ rb_define_method(cFileMagic, "initialize", rb_magic_init, -1);
228
+ rb_define_method(cFileMagic, "close", rb_magic_close, 0);
229
+ rb_define_method(cFileMagic, "closed?", rb_magic_closed_p, 0);
230
+ rb_define_method(cFileMagic, "file", rb_magic_file, -1);
231
+ rb_define_method(cFileMagic, "buffer", rb_magic_buffer, -1);
232
+ rb_define_method(cFileMagic, "descriptor", rb_magic_descriptor, -1);
233
+ rb_define_method(cFileMagic, "flags", rb_magic_getflags, 0);
234
+ rb_define_method(cFileMagic, "flags=", rb_magic_setflags, 1);
235
+ rb_define_method(cFileMagic, "list", rb_magic_list, -1);
236
+ rb_define_method(cFileMagic, "load", rb_magic_load, -1);
237
+ rb_define_method(cFileMagic, "check", rb_magic_check, -1);
238
+ rb_define_method(cFileMagic, "compile", rb_magic_compile, -1);
223
239
 
224
240
  rb_alias(cFileMagic, rb_intern("valid?"), rb_intern("check"));
225
241
 
@@ -267,6 +283,15 @@ Init_ruby_filemagic() {
267
283
  #ifdef MAGIC_APPLE
268
284
  rb_define_const(cFileMagic, "MAGIC_APPLE", INT2FIX(MAGIC_APPLE));
269
285
  #endif
286
+ #ifdef MAGIC_EXTENSION
287
+ rb_define_const(cFileMagic, "MAGIC_EXTENSION", INT2FIX(MAGIC_EXTENSION));
288
+ #endif
289
+ #ifdef MAGIC_COMPRESS_TRANSP
290
+ rb_define_const(cFileMagic, "MAGIC_COMPRESS_TRANSP", INT2FIX(MAGIC_COMPRESS_TRANSP));
291
+ #endif
292
+ #ifdef MAGIC_NODESC
293
+ rb_define_const(cFileMagic, "MAGIC_NODESC", INT2FIX(MAGIC_NODESC));
294
+ #endif
270
295
  #ifdef MAGIC_NO_CHECK_COMPRESS
271
296
  rb_define_const(cFileMagic, "MAGIC_NO_CHECK_COMPRESS", INT2FIX(MAGIC_NO_CHECK_COMPRESS));
272
297
  #endif
@@ -18,22 +18,22 @@
18
18
  }\
19
19
  }
20
20
 
21
- #define RB_MAGIC_TYPE_FILE magic_file(ms, str)
22
- #define RB_MAGIC_TYPE_BUFFER magic_buffer(ms, str, RSTRING_LEN(arg))
21
+ #define RB_MAGIC_TYPE_FILE type = magic_file(ms, StringValuePtr(arg));
22
+ #define RB_MAGIC_TYPE_BUFFER { char *arg_str = StringValuePtr(arg); type = magic_buffer(ms, arg_str, RSTRING_LEN(arg)); }
23
+ #define RB_MAGIC_TYPE_DESCRIPTOR type = 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 *str, *type;\
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
- if ((type = RB_MAGIC_TYPE_##WHAT) == NULL) {\
35
+ RB_MAGIC_TYPE_##WHAT\
36
+ if (type == NULL) {\
37
37
  rb_raise(rb_FileMagicError, "failed lookup: %s", magic_error(ms));\
38
38
  }\
39
39
  \
@@ -72,6 +72,7 @@ rb_magic_##what(int argc, VALUE *argv, VALUE self) {\
72
72
 
73
73
  static VALUE cFileMagic, rb_FileMagicError;
74
74
 
75
+ static VALUE rb_magic_version(VALUE);
75
76
  static VALUE rb_magic_getpath(VALUE);
76
77
  static VALUE rb_magic_flags(VALUE, VALUE);
77
78
 
@@ -84,6 +85,7 @@ static VALUE rb_magic_closed_p(VALUE);
84
85
 
85
86
  static VALUE rb_magic_file(int, VALUE*, VALUE);
86
87
  static VALUE rb_magic_buffer(int, VALUE*, VALUE);
88
+ static VALUE rb_magic_descriptor(int, VALUE*, VALUE);
87
89
 
88
90
  static VALUE rb_magic_getflags(VALUE);
89
91
  static VALUE rb_magic_setflags(VALUE, VALUE);
Binary file
@@ -3,7 +3,7 @@ class FileMagic
3
3
  module Version
4
4
 
5
5
  MAJOR = 0
6
- MINOR = 6
6
+ MINOR = 7
7
7
  TINY = 3
8
8
 
9
9
  class << self
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 only the MIME type
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 translate unprint chars
32
+ :raw, # Don't convert unprintable chars
28
33
  :error, # Handle ENOENT etc as real errors
29
- :mime_encoding, # Return only the MIME encoding
34
+ :mime_encoding, # Return the MIME encoding
30
35
  :mime, # MAGIC_MIME_TYPE | MAGIC_MIME_ENCODING
31
- :apple, # Return the Apple creator and type
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 ascii/tokens
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
@@ -26,7 +26,10 @@ magic file from #{FileMagic.path}
26
26
 
27
27
  if File.symlink?(path_to('pylink'))
28
28
  res = fm.file(path_to('pylink'))
29
- assert_equal("symbolic link to `pyfile'", res.strip)
29
+ assert_equal(match_version(
30
+ 0 => "symbolic link to `pyfile'",
31
+ 5.22 => 'symbolic link to pyfile'
32
+ ), res.strip)
30
33
  end
31
34
 
32
35
  fm.close
@@ -59,6 +62,61 @@ magic file from #{FileMagic.path}
59
62
  assert_equal('POSIX shell script, ASCII text executable', res)
60
63
  end
61
64
 
65
+ def test_nil_buffer
66
+ fm = FileMagic.new(FileMagic::MAGIC_NONE)
67
+ assert_raise(TypeError) { fm.buffer(nil) }
68
+ fm.close
69
+ end
70
+
71
+ def test_descriptor
72
+ fm = FileMagic.new(FileMagic::MAGIC_NONE)
73
+
74
+ python_script = match_version(
75
+ 0 => 'a python script, ASCII text executable',
76
+ 5.11 => 'Python script, ASCII text executable'
77
+ )
78
+
79
+ fd_for('pyfile') { |fd|
80
+ res = fm.descriptor(fd)
81
+ assert_equal(python_script, res)
82
+ }
83
+
84
+ if File.symlink?(path_to('pylink'))
85
+ fd_for('pylink') { |fd|
86
+ res = fm.descriptor(fd)
87
+ assert_equal(python_script, res.strip)
88
+ }
89
+ end
90
+
91
+ fm.close
92
+ fm = FileMagic.new(FileMagic::MAGIC_SYMLINK)
93
+
94
+ fd_for('pylink') { |fd|
95
+ res = fm.descriptor(fd)
96
+ assert_equal(python_script, res)
97
+ }
98
+
99
+ fm.close
100
+ fm = FileMagic.new(FileMagic::MAGIC_SYMLINK | FileMagic::MAGIC_MIME)
101
+
102
+ fd_for('pylink') { |fd|
103
+ res = fm.descriptor(fd)
104
+ assert_equal('text/plain; charset=us-ascii', res)
105
+ }
106
+
107
+ fm.close
108
+ fm = FileMagic.new(FileMagic::MAGIC_COMPRESS)
109
+
110
+ fd_for('pyfile-compressed.gz') { |fd|
111
+ res = fm.descriptor(fd)
112
+ gzip_compressed = 'gzip compressed data, was "pyfile-compressed"'
113
+ assert_match(Gem.win_platform? ? /^#{gzip_compressed}/ :
114
+ /^#{python_script} \(#{gzip_compressed}/, res)
115
+ }
116
+
117
+ fm.close
118
+ end
119
+
62
120
  def test_check
63
121
  return if Gem.win_platform?
64
122
  fm = FileMagic.new(FileMagic::MAGIC_NONE)
@@ -72,7 +130,10 @@ magic file from #{FileMagic.path}
72
130
  fm = FileMagic.new(FileMagic::MAGIC_NONE)
73
131
  res = silence_stderr { fm.check(path_to('perl.mgc')) }
74
132
  fm.close
75
- assert(res)
133
+ assert(match_version(
134
+ 0 => res,
135
+ 5.39 => !res
136
+ ))
76
137
  end
77
138
 
78
139
  def test_compile
@@ -180,7 +241,8 @@ magic file from #{FileMagic.path}
180
241
  assert_equal(match_version(
181
242
  0 => 'application/vnd.ms-office',
182
243
  5.11 => 'application/msword',
183
- 5.14 => 'application/vnd.ms-office'
244
+ 5.14 => 'application/vnd.ms-office',
245
+ 5.39 => 'application/vnd.ms-excel'
184
246
  ), fm.file(path_to('excel-example.xls')))
185
247
  end
186
248
 
@@ -213,6 +275,12 @@ magic file from #{FileMagic.path}
213
275
  File.join(dir, file)
214
276
  end
215
277
 
278
+ def fd_for(file)
279
+ File.open(path_to(file)) { |f| yield f.fileno }
280
+ rescue Errno::EBADF => err
281
+ warn err.to_s
282
+ end
283
+
216
284
  def silence_stderr
217
285
  require 'nuggets/io/redirect'
218
286
  $stderr.redirect { yield }
data/test/pylink ADDED
@@ -0,0 +1 @@
1
+ test/pyfile
metadata CHANGED
@@ -1,15 +1,15 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: ruby-filemagic
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.6.3
4
+ version: 0.7.3
5
5
  platform: ruby
6
6
  authors:
7
7
  - Travis Whitton
8
8
  - Jens Wille
9
- autorequire:
9
+ autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2015-02-06 00:00:00.000000000 Z
12
+ date: 2022-01-07 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: hen
@@ -17,20 +17,20 @@ dependencies:
17
17
  requirements:
18
18
  - - "~>"
19
19
  - !ruby/object:Gem::Version
20
- version: '0.8'
20
+ version: '0.9'
21
21
  - - ">="
22
22
  - !ruby/object:Gem::Version
23
- version: 0.8.1
23
+ version: 0.9.1
24
24
  type: :development
25
25
  prerelease: false
26
26
  version_requirements: !ruby/object:Gem::Requirement
27
27
  requirements:
28
28
  - - "~>"
29
29
  - !ruby/object:Gem::Version
30
- version: '0.8'
30
+ version: '0.9'
31
31
  - - ">="
32
32
  - !ruby/object:Gem::Version
33
- version: 0.8.1
33
+ version: 0.9.1
34
34
  - !ruby/object:Gem::Dependency
35
35
  name: rake
36
36
  requirement: !ruby/object:Gem::Requirement
@@ -83,7 +83,9 @@ extra_rdoc_files:
83
83
  - ChangeLog
84
84
  - ext/filemagic/filemagic.c
85
85
  files:
86
+ - CONTRIBUTING.md
86
87
  - ChangeLog
88
+ - Dockerfile
87
89
  - README
88
90
  - Rakefile
89
91
  - TODO
@@ -110,13 +112,15 @@ licenses:
110
112
  metadata: {}
111
113
  post_install_message: |2+
112
114
 
113
- ruby-filemagic-0.6.3 [2015-02-06]:
115
+ ruby-filemagic-0.7.3 [2022-01-07]:
114
116
 
115
- * Fixed build error with Clang (issue #13 by Stan Carver II).
117
+ * Dockerfile to build native extension (pull request #26 by Pavel Lobashov).
118
+ * Include paths for ARM-based Apple Macs (Apple Silicon) (pull request #35 by
119
+ @545ch4).
116
120
 
117
121
  rdoc_options:
118
122
  - "--title"
119
- - ruby-filemagic Application documentation (v0.6.3)
123
+ - ruby-filemagic Application documentation (v0.7.3)
120
124
  - "--charset"
121
125
  - UTF-8
122
126
  - "--line-numbers"
@@ -136,9 +140,9 @@ required_rubygems_version: !ruby/object:Gem::Requirement
136
140
  - !ruby/object:Gem::Version
137
141
  version: '0'
138
142
  requirements: []
139
- rubyforge_project:
140
- rubygems_version: 2.4.5
141
- signing_key:
143
+ rubygems_version: 3.2.5
144
+ signing_key:
142
145
  specification_version: 4
143
146
  summary: Ruby bindings to the magic(4) library
144
147
  test_files: []
148
+ ...
data/test/pylink DELETED
@@ -1 +0,0 @@
1
- """