ruby-filemagic 0.4.2 → 0.5.0

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: a838370185e74426017deaa1c9b9e41935636c68
4
+ data.tar.gz: c7fc52e6fd4a78dea2ede8b329641cc2f4a6fa17
5
+ SHA512:
6
+ metadata.gz: c05274940e05af64ac2609e9a03d3fc22a4175f61d1e29d83e30c85a129531953383952d82e491040431d9127f7fecb5fde61c38a30966f793eda611194d074c
7
+ data.tar.gz: 05869472cbb9bfec6be74f95976a8ea26d3dbca77070578a6e69505d66882e480047a6df765973cbaebdcc410de57bb9a7b72a85a91cdc08f9356d80b0e61e91
data/ChangeLog CHANGED
@@ -1,5 +1,13 @@
1
+ # markup: rd
2
+
1
3
  = Revision history for ruby-filemagic
2
4
 
5
+ == 0.5.0 [2013-12-19]
6
+
7
+ * Removed usage of +RARRAY_PTR+ (cf. Ruby bug
8
+ {#8399}[https://bugs.ruby-lang.org/issues/8399]).
9
+ * Housekeeping.
10
+
3
11
  == 0.4.2 [2010-09-16]
4
12
 
5
13
  * Not all versions/distributions have file/patchlevel.h
data/README CHANGED
@@ -2,14 +2,14 @@
2
2
 
3
3
  == VERSION
4
4
 
5
- This documentation refers to filemagic version 0.4.2
5
+ This documentation refers to filemagic version 0.5.0
6
6
 
7
7
 
8
8
  == DESCRIPTION
9
9
 
10
10
  === Revised version
11
11
 
12
- September 12, 2008 Jens Wille <jens.wille@uni-koeln.de>
12
+ September 12, 2008 Jens Wille <jens.wille@gmail.com>
13
13
 
14
14
  Similar to Ricardo[http://github.com/ricardochimal/ruby-filemagic]
15
15
  I wanted this project to make some progress. My needs went a bit
@@ -43,16 +43,16 @@ Travis
43
43
  == LINKS
44
44
 
45
45
  <b></b>
46
- Homepage:: <http://grub.ath.cx/filemagic/>
47
- Documentation:: <http://ruby-filemagic.rubyforge.org/>
48
- Source code:: <http://github.com/blackwinter/ruby-filemagic>
49
- Rubyforge project:: <http://rubyforge.org/projects/ruby-filemagic>
46
+ Homepage (defunct):: http://grub.ath.cx/filemagic/
47
+ Documentation:: http://blackwinter.github.com/ruby-filemagic
48
+ Source code:: http://github.com/blackwinter/ruby-filemagic
49
+ RubyGem:: http://rubygems.org/gems/ruby-filemagic
50
50
 
51
51
 
52
52
  == AUTHORS
53
53
 
54
54
  * Travis Whitton <mailto:tinymountain@gmail.com> (Original author)
55
- * Jens Wille <mailto:jens.wille@uni-koeln.de>
55
+ * Jens Wille <mailto:jens.wille@gmail.com>
56
56
 
57
57
 
58
58
  == CREDITS
data/Rakefile CHANGED
@@ -1,24 +1,25 @@
1
- require %q{./lib/filemagic/version}
1
+ require File.expand_path(%q{../lib/filemagic/version}, __FILE__)
2
2
 
3
3
  begin
4
4
  require 'hen'
5
5
 
6
6
  Hen.lay! {{
7
- :rubyforge => {
8
- :package => 'ruby-filemagic',
9
- :project => 'ruby-filemagic',
10
- :rdoc_dir => nil
11
- },
12
-
13
7
  :gem => {
14
- :version => FileMagic::VERSION,
15
- :summary => 'Ruby bindings to the magic(4) library',
16
- :authors => ['Travis Whitton', 'Jens Wille'],
17
- :email => ['tinymountain@gmail.com', 'jens.wille@uni-koeln.de'],
18
- :homepage => 'http://ruby-filemagic.rubyforge.org/',
19
- :files => FileList['lib/**/*.rb', 'ext/**/*.[ch]', 'test/*'].to_a,
20
- :extensions => FileList['ext/**/extconf.rb'].to_a,
21
- :extra_files => FileList['[A-Z]*', 'info/*'].to_a
8
+ :name => %q{ruby-filemagic},
9
+ :version => FileMagic::VERSION,
10
+ :summary => 'Ruby bindings to the magic(4) library',
11
+ :authors => ['Travis Whitton', 'Jens Wille'],
12
+ :email => ['tinymountain@gmail.com', 'jens.wille@gmail.com'],
13
+ :license => %q{Ruby},
14
+ :homepage => :blackwinter,
15
+ :extra_files => FileList['info/*'].to_a,
16
+ :dependencies => %w[],
17
+ :extension => {
18
+ :name => 'filemagic',
19
+ :ext_dir => 'ext',
20
+ :lib_dir => 'lib',
21
+ :cross_compile => false
22
+ }
22
23
  }
23
24
  }}
24
25
  rescue LoadError => err
@@ -32,7 +32,8 @@ rb_magic_new(int argc, VALUE *argv, VALUE class) {
32
32
  args[1] = rb_hash_new();
33
33
  }
34
34
 
35
- args[0] = rb_magic_flags_to_int(argc, argv);
35
+ args[0] = rb_magic_flags_to_int(rb_ary_new4(argc, argv));
36
+
36
37
  if ((cookie = magic_open(NUM2INT(args[0]))) == NULL) {
37
38
  rb_fatal("out of memory");
38
39
  }
@@ -165,7 +166,7 @@ rb_magic_setflags(VALUE self, VALUE flags) {
165
166
  magic_t cookie;
166
167
 
167
168
  flags = rb_Array(flags);
168
- flags = rb_magic_flags_to_int(RARRAY_LEN(flags), RARRAY_PTR(flags));
169
+ flags = rb_magic_flags_to_int(flags);
169
170
  rb_iv_set(self, "_flags", flags);
170
171
 
171
172
  GetMagicCookie(self, cookie);
@@ -205,13 +206,13 @@ rb_magic_compile(VALUE self, VALUE file) {
205
206
  }
206
207
 
207
208
  static VALUE
208
- rb_magic_flags_to_int(int argc, VALUE *argv) {
209
+ rb_magic_flags_to_int(VALUE ary) {
209
210
  VALUE map = rb_const_get(cFileMagic, rb_intern("FLAGS_BY_SYM"));
210
211
  VALUE f, g;
211
212
  int i = MAGIC_NONE, j;
212
213
 
213
- for (j = 0; j < argc; j++) {
214
- f = argv[j];
214
+ for (j = 0; j < RARRAY_LEN(ary); j++) {
215
+ f = rb_ary_entry(ary, j);
215
216
 
216
217
  switch (TYPE(f)) {
217
218
  case T_SYMBOL:
@@ -222,7 +223,8 @@ rb_magic_flags_to_int(int argc, VALUE *argv) {
222
223
  else {
223
224
  f = rb_funcall(f, rb_intern("inspect"), 0);
224
225
  rb_raise(rb_eArgError,
225
- "%s: %s", NIL_P(g) ? "no such flag" : "flag not available",
226
+ "%s: %s",
227
+ NIL_P(g) ? "no such flag" : "flag not available",
226
228
  StringValueCStr(f)
227
229
  );
228
230
  break;
@@ -269,9 +271,9 @@ rb_magic_free(magic_t cookie) {
269
271
 
270
272
  void
271
273
  Init_filemagic() {
274
+ char version[8] = "0";
272
275
  cFileMagic = rb_define_class("FileMagic", rb_cObject);
273
276
 
274
- char version[8] = "0";
275
277
  #ifdef FILE_VERSION_MAJOR
276
278
  sprintf(version, "%d.%02d", FILE_VERSION_MAJOR, patchlevel);
277
279
  #endif
@@ -12,20 +12,17 @@
12
12
  #ifndef RSTRING_LEN
13
13
  #define RSTRING_LEN(s) (RSTRING(s)->len)
14
14
  #endif
15
- #ifndef RSTRING_PTR
16
- #define RSTRING_PTR(s) (RSTRING(s)->ptr)
17
- #endif
18
15
  #ifndef RARRAY_LEN
19
16
  #define RARRAY_LEN(s) (RARRAY(s)->len)
20
17
  #endif
21
- #ifndef RARRAY_PTR
22
- #define RARRAY_PTR(s) (RARRAY(s)->ptr)
23
- #endif
24
18
 
25
19
  #define GetMagicCookie(obj, cookie) {\
26
- if (RTEST(rb_magic_closed_p(obj)))\
20
+ if (RTEST(rb_magic_closed_p(obj))) {\
27
21
  rb_raise(rb_eRuntimeError, "closed stream");\
28
- Data_Get_Struct(obj, struct magic_set, cookie);\
22
+ }\
23
+ else {\
24
+ Data_Get_Struct((obj), struct magic_set, (cookie));\
25
+ }\
29
26
  }
30
27
 
31
28
  static VALUE cFileMagic, rb_FileMagicError;
@@ -42,7 +39,7 @@ static VALUE rb_magic_setflags(VALUE, VALUE);
42
39
  static VALUE rb_magic_check(int, VALUE*, VALUE);
43
40
  static VALUE rb_magic_compile(VALUE, VALUE);
44
41
 
45
- static VALUE rb_magic_flags_to_int(int, VALUE*);
42
+ static VALUE rb_magic_flags_to_int(VALUE);
46
43
  static VALUE rb_magic_apply_simple(VALUE, const char*, VALUE);
47
44
 
48
45
  static void rb_magic_free(magic_t);
@@ -39,7 +39,7 @@ class FileMagic
39
39
  # Map flag values to their names (Integer => :name).
40
40
  FLAGS_BY_INT = FLAGS_BY_SYM.invert.update(0 => :none)
41
41
 
42
- # Extract "simple" MIME type
42
+ # Extract "simple" MIME type.
43
43
  SIMPLE_RE = %r{([.\w\/-]+)}
44
44
 
45
45
  @fm = Hash.new { |fm, flags|
@@ -62,7 +62,6 @@ class File
62
62
  def self.file_type(file, *flags)
63
63
  FileMagic.fm(*flags).file(file.respond_to?(:path) ? file.path : file)
64
64
  rescue FileMagic::FileMagicError
65
- nil
66
65
  end
67
66
 
68
67
  end
@@ -74,7 +73,6 @@ class String
74
73
  def self.file_type(string, *flags)
75
74
  FileMagic.fm(*flags).buffer(string)
76
75
  rescue FileMagic::FileMagicError
77
- nil
78
76
  end
79
77
 
80
78
  end
@@ -3,8 +3,8 @@ class FileMagic
3
3
  module Version
4
4
 
5
5
  MAJOR = 0
6
- MINOR = 4
7
- TINY = 2
6
+ MINOR = 5
7
+ TINY = 0
8
8
 
9
9
  class << self
10
10
 
@@ -1,7 +1,4 @@
1
1
  require 'test/unit'
2
-
3
- top_dir = File.join(File.dirname(__FILE__), '..')
4
- $:.unshift(File.join(top_dir, 'lib'), File.join(top_dir, 'ext'))
5
2
  require 'filemagic'
6
3
 
7
4
  class TestFileMagic < Test::Unit::TestCase
@@ -10,7 +7,7 @@ class TestFileMagic < Test::Unit::TestCase
10
7
  fm = FileMagic.new(FileMagic::MAGIC_NONE)
11
8
 
12
9
  res = fm.file(path_to('pyfile'))
13
- assert_equal('a python script text executable', res)
10
+ assert_equal('Python script, ASCII text executable', res)
14
11
 
15
12
  if File.symlink?(path_to('pylink'))
16
13
  res = fm.file(path_to('pylink'))
@@ -21,7 +18,7 @@ class TestFileMagic < Test::Unit::TestCase
21
18
  fm = FileMagic.new(FileMagic::MAGIC_SYMLINK)
22
19
 
23
20
  res = fm.file(path_to('pylink'))
24
- assert_equal('a python script text executable', res)
21
+ assert_equal('Python script, ASCII text executable', res)
25
22
 
26
23
  fm.close
27
24
  fm = FileMagic.new(FileMagic::MAGIC_SYMLINK | FileMagic::MAGIC_MIME)
@@ -33,7 +30,7 @@ class TestFileMagic < Test::Unit::TestCase
33
30
  fm = FileMagic.new(FileMagic::MAGIC_COMPRESS)
34
31
 
35
32
  res = fm.file(path_to('pyfile-compressed.gz'))
36
- assert_match(/^a python script text executable \(gzip compressed data, was "pyfile-compressed", from Unix/, res)
33
+ assert_match(/^Python script, ASCII text executable \(gzip compressed data, was "pyfile-compressed", from Unix/, res)
37
34
 
38
35
  fm.close
39
36
  end
@@ -42,12 +39,12 @@ class TestFileMagic < Test::Unit::TestCase
42
39
  fm = FileMagic.new(FileMagic::MAGIC_NONE)
43
40
  res = fm.buffer("#!/bin/sh\n")
44
41
  fm.close
45
- assert_match(/shell script text executable$/, res)
42
+ assert_equal('POSIX shell script, ASCII text executable', res)
46
43
  end
47
44
 
48
45
  def test_check
49
46
  fm = FileMagic.new(FileMagic::MAGIC_NONE)
50
- res = fm.check(path_to('perl'))
47
+ res = silence_stderr { fm.check(path_to('perl')) }
51
48
  fm.close
52
49
  assert_equal(0, res)
53
50
  end
@@ -67,7 +64,7 @@ class TestFileMagic < Test::Unit::TestCase
67
64
  block_fm = fm
68
65
  fm.file(path_to('pyfile'))
69
66
  }
70
- assert_equal('a python script text executable', res)
67
+ assert_equal('Python script, ASCII text executable', res)
71
68
  assert block_fm.closed?
72
69
  end
73
70
 
@@ -100,7 +97,7 @@ class TestFileMagic < Test::Unit::TestCase
100
97
  def test_mahoro_file
101
98
  fm = FileMagic.new
102
99
  fm.flags = FileMagic::MAGIC_NONE
103
- assert_equal('ASCII C program text', fm.file(path_to('mahoro.c')))
100
+ assert_equal('C source, ASCII text', fm.file(path_to('mahoro.c')))
104
101
  end
105
102
 
106
103
  def test_mahoro_mime_file
@@ -112,7 +109,7 @@ class TestFileMagic < Test::Unit::TestCase
112
109
  def test_mahoro_buffer
113
110
  fm = FileMagic.new
114
111
  fm.flags = FileMagic::MAGIC_NONE
115
- assert_equal('ASCII C program text', fm.buffer(File.read(path_to('mahoro.c'))))
112
+ assert_equal('C source, ASCII text', fm.buffer(File.read(path_to('mahoro.c'))))
116
113
  end
117
114
 
118
115
  def test_mahoro_mime_buffer
@@ -123,7 +120,7 @@ class TestFileMagic < Test::Unit::TestCase
123
120
 
124
121
  def test_mahoro_valid
125
122
  fm = FileMagic.new
126
- assert(fm.valid?, 'Default database was not valid.')
123
+ assert(silence_stderr { fm.valid? }, 'Default database was not valid.')
127
124
  end
128
125
 
129
126
  # test abbreviating mime types
@@ -137,7 +134,7 @@ class TestFileMagic < Test::Unit::TestCase
137
134
  fm.simplified = true
138
135
  assert fm.simplified?
139
136
  assert_equal('text/plain', fm.file(path_to('perl')))
140
- assert_equal('application/vnd.ms-office', fm.file(path_to('excel-example.xls')))
137
+ assert_equal('application/msword', fm.file(path_to('excel-example.xls')))
141
138
  end
142
139
 
143
140
  # utility methods:
@@ -146,4 +143,11 @@ class TestFileMagic < Test::Unit::TestCase
146
143
  File.join(dir, file)
147
144
  end
148
145
 
146
+ def silence_stderr
147
+ require 'nuggets/io/redirect'
148
+ $stderr.redirect { yield }
149
+ rescue LoadError
150
+ yield
151
+ end
152
+
149
153
  end
metadata CHANGED
@@ -1,98 +1,85 @@
1
- --- !ruby/object:Gem::Specification
1
+ --- !ruby/object:Gem::Specification
2
2
  name: ruby-filemagic
3
- version: !ruby/object:Gem::Version
4
- hash: 11
5
- prerelease: false
6
- segments:
7
- - 0
8
- - 4
9
- - 2
10
- version: 0.4.2
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.5.0
11
5
  platform: ruby
12
- authors:
6
+ authors:
13
7
  - Travis Whitton
14
8
  - Jens Wille
15
9
  autorequire:
16
10
  bindir: bin
17
11
  cert_chain: []
18
-
19
- date: 2010-09-16 00:00:00 +02:00
20
- default_executable:
12
+ date: 2013-12-19 00:00:00.000000000 Z
21
13
  dependencies: []
22
-
23
14
  description: Ruby bindings to the magic(4) library
24
- email:
15
+ email:
25
16
  - tinymountain@gmail.com
26
- - jens.wille@uni-koeln.de
17
+ - jens.wille@gmail.com
27
18
  executables: []
28
-
29
- extensions:
19
+ extensions:
30
20
  - ext/extconf.rb
31
- extra_rdoc_files:
32
- - ChangeLog
21
+ extra_rdoc_files:
33
22
  - README
34
- files:
23
+ - ChangeLog
24
+ - ext/filemagic.c
25
+ files:
26
+ - lib/filemagic.rb
35
27
  - lib/filemagic/ext.rb
36
28
  - lib/filemagic/version.rb
37
- - lib/filemagic.rb
38
- - ext/filemagic.h
39
- - ext/filemagic.c
40
- - test/pyfile
41
- - test/mahoro.c
42
- - test/pylink
43
- - test/pyfile-compressed.gz
44
- - test/perl
45
- - test/leaktest.rb
46
- - test/filemagic_test.rb
47
- - test/excel-example.xls
48
- - README
29
+ - info/example.rb
30
+ - info/filemagic.rd
49
31
  - ChangeLog
32
+ - README
50
33
  - Rakefile
51
34
  - TODO
52
- - info/filemagic.rd
53
- - info/example.rb
54
35
  - ext/extconf.rb
55
- has_rdoc: true
56
- homepage: http://ruby-filemagic.rubyforge.org/
57
- licenses: []
36
+ - ext/filemagic.c
37
+ - ext/filemagic.h
38
+ - test/excel-example.xls
39
+ - test/filemagic_test.rb
40
+ - test/leaktest.rb
41
+ - test/mahoro.c
42
+ - test/perl
43
+ - test/pyfile
44
+ - test/pyfile-compressed.gz
45
+ - test/pylink
46
+ homepage: http://github.com/blackwinter/ruby-filemagic
47
+ licenses:
48
+ - Ruby
49
+ metadata: {}
50
+ post_install_message: |2+
58
51
 
59
- post_install_message:
60
- rdoc_options:
61
- - --title
62
- - ruby-filemagic Application documentation
63
- - --main
64
- - README
65
- - --line-numbers
66
- - --inline-source
67
- - --charset
52
+ ruby-filemagic-0.5.0 [2013-12-19]:
53
+
54
+ * Removed usage of +RARRAY_PTR+ (cf. Ruby bug
55
+ {#8399}[https://bugs.ruby-lang.org/issues/8399]).
56
+ * Housekeeping.
57
+
58
+ rdoc_options:
59
+ - "--title"
60
+ - ruby-filemagic Application documentation (v0.5.0)
61
+ - "--charset"
68
62
  - UTF-8
69
- - --all
70
- require_paths:
63
+ - "--line-numbers"
64
+ - "--all"
65
+ - "--main"
66
+ - README
67
+ require_paths:
71
68
  - lib
72
- required_ruby_version: !ruby/object:Gem::Requirement
73
- none: false
74
- requirements:
69
+ required_ruby_version: !ruby/object:Gem::Requirement
70
+ requirements:
75
71
  - - ">="
76
- - !ruby/object:Gem::Version
77
- hash: 3
78
- segments:
79
- - 0
80
- version: "0"
81
- required_rubygems_version: !ruby/object:Gem::Requirement
82
- none: false
83
- requirements:
72
+ - !ruby/object:Gem::Version
73
+ version: '0'
74
+ required_rubygems_version: !ruby/object:Gem::Requirement
75
+ requirements:
84
76
  - - ">="
85
- - !ruby/object:Gem::Version
86
- hash: 3
87
- segments:
88
- - 0
89
- version: "0"
77
+ - !ruby/object:Gem::Version
78
+ version: '0'
90
79
  requirements: []
91
-
92
- rubyforge_project: ruby-filemagic
93
- rubygems_version: 1.3.7
80
+ rubyforge_project:
81
+ rubygems_version: 2.1.11
94
82
  signing_key:
95
- specification_version: 3
83
+ specification_version: 4
96
84
  summary: Ruby bindings to the magic(4) library
97
85
  test_files: []
98
-