magic 0.2.4 → 0.2.5
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.
- data/README.rdoc +0 -11
- data/lib/magic.rb +2 -0
- metadata +42 -39
- data/.document +0 -5
- data/.gitignore +0 -22
- data/Rakefile +0 -83
- data/VERSION +0 -1
- data/magic.gemspec +0 -91
- data/test/fixtures/filelogo.jpg +0 -0
- data/test/fixtures/magic.txt +0 -1
- data/test/fixtures/magic_empty +0 -1
- data/test/fixtures/magic_jpeg +0 -29
- data/test/helper.rb +0 -13
- data/test/test_magic.rb +0 -47
data/README.rdoc
CHANGED
@@ -16,17 +16,6 @@ See {project page}[http://jah.pl/projects/magic.html] for details.
|
|
16
16
|
* {issue tracker}[http://github.com/qoobaa/magic/issues]
|
17
17
|
* rdoc[http://qoobaa.github.com/magic]
|
18
18
|
|
19
|
-
== Note on Patches/Pull Requests
|
20
|
-
|
21
|
-
* Fork the project.
|
22
|
-
* Make your feature addition or bug fix.
|
23
|
-
* Add tests for it. This is important so I don't break it in a future
|
24
|
-
version unintentionally.
|
25
|
-
* Commit, do not mess with rakefile, version, or history. (if you want
|
26
|
-
to have your own version, that is fine but bump version in a commit
|
27
|
-
by itself I can ignore when I pull)
|
28
|
-
* Send me a pull request. Bonus points for topic branches.
|
29
|
-
|
30
19
|
== Copyright
|
31
20
|
|
32
21
|
Copyright (c) 2010 Jakub Kuźma. See
|
data/lib/magic.rb
CHANGED
metadata
CHANGED
@@ -1,7 +1,12 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: magic
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
|
4
|
+
prerelease: false
|
5
|
+
segments:
|
6
|
+
- 0
|
7
|
+
- 2
|
8
|
+
- 5
|
9
|
+
version: 0.2.5
|
5
10
|
platform: ruby
|
6
11
|
authors:
|
7
12
|
- "Jakub Ku\xC5\xBAma"
|
@@ -9,59 +14,54 @@ autorequire:
|
|
9
14
|
bindir: bin
|
10
15
|
cert_chain: []
|
11
16
|
|
12
|
-
date: 2010-
|
17
|
+
date: 2010-04-20 00:00:00 +02:00
|
13
18
|
default_executable:
|
14
19
|
dependencies:
|
15
20
|
- !ruby/object:Gem::Dependency
|
16
21
|
name: ffi
|
17
|
-
|
18
|
-
|
19
|
-
version_requirements: !ruby/object:Gem::Requirement
|
22
|
+
prerelease: false
|
23
|
+
requirement: &id001 !ruby/object:Gem::Requirement
|
20
24
|
requirements:
|
21
25
|
- - ">="
|
22
26
|
- !ruby/object:Gem::Version
|
23
|
-
|
24
|
-
|
27
|
+
segments:
|
28
|
+
- 0
|
29
|
+
- 6
|
30
|
+
- 3
|
31
|
+
version: 0.6.3
|
32
|
+
type: :runtime
|
33
|
+
version_requirements: *id001
|
25
34
|
- !ruby/object:Gem::Dependency
|
26
35
|
name: test-unit
|
27
|
-
|
28
|
-
|
29
|
-
version_requirements: !ruby/object:Gem::Requirement
|
36
|
+
prerelease: false
|
37
|
+
requirement: &id002 !ruby/object:Gem::Requirement
|
30
38
|
requirements:
|
31
39
|
- - ">="
|
32
40
|
- !ruby/object:Gem::Version
|
41
|
+
segments:
|
42
|
+
- 2
|
43
|
+
- 0
|
33
44
|
version: "2.0"
|
34
|
-
|
45
|
+
type: :development
|
46
|
+
version_requirements: *id002
|
35
47
|
description: Ruby FFI bindings to libmagic
|
36
48
|
email: qoobaa@gmail.com
|
37
49
|
executables: []
|
38
50
|
|
39
51
|
extensions: []
|
40
52
|
|
41
|
-
extra_rdoc_files:
|
42
|
-
|
43
|
-
- README.rdoc
|
53
|
+
extra_rdoc_files: []
|
54
|
+
|
44
55
|
files:
|
45
|
-
- .document
|
46
|
-
- .gitignore
|
47
|
-
- LICENSE
|
48
|
-
- README.rdoc
|
49
|
-
- Rakefile
|
50
|
-
- VERSION
|
51
56
|
- lib/magic.rb
|
52
|
-
- lib/magic/api.rb
|
53
|
-
- lib/magic/constants.rb
|
54
57
|
- lib/magic/database.rb
|
55
58
|
- lib/magic/errors.rb
|
56
|
-
- magic.
|
57
|
-
-
|
58
|
-
-
|
59
|
-
-
|
60
|
-
- test/fixtures/magic_jpeg
|
61
|
-
- test/helper.rb
|
62
|
-
- test/test_magic.rb
|
59
|
+
- lib/magic/api.rb
|
60
|
+
- lib/magic/constants.rb
|
61
|
+
- LICENSE
|
62
|
+
- README.rdoc
|
63
63
|
has_rdoc: true
|
64
|
-
homepage: http://
|
64
|
+
homepage: http://jah.pl/projects/magic.html
|
65
65
|
licenses: []
|
66
66
|
|
67
67
|
post_install_message: |
|
@@ -91,29 +91,32 @@ post_install_message: |
|
|
91
91
|
| |
|
92
92
|
+-------------------------------------------------------------------+
|
93
93
|
|
94
|
-
rdoc_options:
|
95
|
-
|
94
|
+
rdoc_options: []
|
95
|
+
|
96
96
|
require_paths:
|
97
97
|
- lib
|
98
98
|
required_ruby_version: !ruby/object:Gem::Requirement
|
99
99
|
requirements:
|
100
100
|
- - ">="
|
101
101
|
- !ruby/object:Gem::Version
|
102
|
+
segments:
|
103
|
+
- 0
|
102
104
|
version: "0"
|
103
|
-
version:
|
104
105
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
105
106
|
requirements:
|
106
107
|
- - ">="
|
107
108
|
- !ruby/object:Gem::Version
|
108
|
-
|
109
|
-
|
109
|
+
segments:
|
110
|
+
- 1
|
111
|
+
- 3
|
112
|
+
- 6
|
113
|
+
version: 1.3.6
|
110
114
|
requirements: []
|
111
115
|
|
112
116
|
rubyforge_project:
|
113
|
-
rubygems_version: 1.3.
|
117
|
+
rubygems_version: 1.3.6
|
114
118
|
signing_key:
|
115
119
|
specification_version: 3
|
116
120
|
summary: Determine file type and encoding using "magic" numbers
|
117
|
-
test_files:
|
118
|
-
|
119
|
-
- test/helper.rb
|
121
|
+
test_files: []
|
122
|
+
|
data/.document
DELETED
data/.gitignore
DELETED
data/Rakefile
DELETED
@@ -1,83 +0,0 @@
|
|
1
|
-
# encoding: utf-8
|
2
|
-
|
3
|
-
require 'rubygems'
|
4
|
-
require 'rake'
|
5
|
-
|
6
|
-
begin
|
7
|
-
require 'jeweler'
|
8
|
-
Jeweler::Tasks.new do |gem|
|
9
|
-
gem.name = "magic"
|
10
|
-
gem.summary = %Q{Determine file type and encoding using "magic" numbers}
|
11
|
-
gem.description = %Q{Ruby FFI bindings to libmagic}
|
12
|
-
gem.email = "qoobaa@gmail.com"
|
13
|
-
gem.homepage = "http://github.com/qoobaa/magic"
|
14
|
-
gem.authors = ["Jakub Kuźma"]
|
15
|
-
gem.add_dependency "ffi", ">= 0.6.0"
|
16
|
-
gem.add_development_dependency "test-unit", ">= 2.0"
|
17
|
-
# gem is a Gem::Specification... see http://www.rubygems.org/read/chapter/20 for additional settings
|
18
|
-
gem.post_install_message = <<-EOM
|
19
|
-
+-NOTE FOR LINUX USERS----------------------------------------------+
|
20
|
-
| |
|
21
|
-
| Install libmagic using your package manager, e.g. |
|
22
|
-
| |
|
23
|
-
| sudo apt-get install file |
|
24
|
-
| |
|
25
|
-
+-NOTE FOR WINDOWS USERS -------------------------------------------+
|
26
|
-
| |
|
27
|
-
| Install File for Windows from |
|
28
|
-
| |
|
29
|
-
| http://gnuwin32.sourceforge.net/packages/file.htm |
|
30
|
-
| |
|
31
|
-
| You'll also need to set your PATH environment variable to the |
|
32
|
-
| directory of the magic1.dll file |
|
33
|
-
| |
|
34
|
-
| set PATH=C:\\Program Files\\GnuWin32\\bin;%PATH% |
|
35
|
-
| |
|
36
|
-
+-NOTE FOR MAC OS USERS --------------------------------------------+
|
37
|
-
| |
|
38
|
-
| If you don't have libmagic.1.dylib file in your system, you need |
|
39
|
-
| to install it using port command |
|
40
|
-
| |
|
41
|
-
| sudo port install file |
|
42
|
-
| |
|
43
|
-
+-------------------------------------------------------------------+
|
44
|
-
EOM
|
45
|
-
end
|
46
|
-
Jeweler::GemcutterTasks.new
|
47
|
-
rescue LoadError
|
48
|
-
puts "Jeweler (or a dependency) not available. Install it with: gem install jeweler"
|
49
|
-
end
|
50
|
-
|
51
|
-
require 'rake/testtask'
|
52
|
-
Rake::TestTask.new(:test) do |test|
|
53
|
-
test.libs << 'lib' << 'test'
|
54
|
-
test.pattern = 'test/**/test_*.rb'
|
55
|
-
test.verbose = true
|
56
|
-
end
|
57
|
-
|
58
|
-
begin
|
59
|
-
require 'rcov/rcovtask'
|
60
|
-
Rcov::RcovTask.new do |test|
|
61
|
-
test.libs << 'test'
|
62
|
-
test.pattern = 'test/**/test_*.rb'
|
63
|
-
test.verbose = true
|
64
|
-
end
|
65
|
-
rescue LoadError
|
66
|
-
task :rcov do
|
67
|
-
abort "RCov is not available. In order to run rcov, you must: sudo gem install spicycode-rcov"
|
68
|
-
end
|
69
|
-
end
|
70
|
-
|
71
|
-
task :test => :check_dependencies
|
72
|
-
|
73
|
-
task :default => :test
|
74
|
-
|
75
|
-
require 'rake/rdoctask'
|
76
|
-
Rake::RDocTask.new do |rdoc|
|
77
|
-
version = File.exist?('VERSION') ? File.read('VERSION') : ""
|
78
|
-
|
79
|
-
rdoc.rdoc_dir = 'rdoc'
|
80
|
-
rdoc.title = "magic #{version}"
|
81
|
-
rdoc.rdoc_files.include('README*')
|
82
|
-
rdoc.rdoc_files.include('lib/**/*.rb')
|
83
|
-
end
|
data/VERSION
DELETED
@@ -1 +0,0 @@
|
|
1
|
-
0.2.4
|
data/magic.gemspec
DELETED
@@ -1,91 +0,0 @@
|
|
1
|
-
# Generated by jeweler
|
2
|
-
# DO NOT EDIT THIS FILE DIRECTLY
|
3
|
-
# Instead, edit Jeweler::Tasks in Rakefile, and run the gemspec command
|
4
|
-
# -*- encoding: utf-8 -*-
|
5
|
-
|
6
|
-
Gem::Specification.new do |s|
|
7
|
-
s.name = %q{magic}
|
8
|
-
s.version = "0.2.4"
|
9
|
-
|
10
|
-
s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
|
11
|
-
s.authors = ["Jakub Kuźma"]
|
12
|
-
s.date = %q{2010-02-10}
|
13
|
-
s.description = %q{Ruby FFI bindings to libmagic}
|
14
|
-
s.email = %q{qoobaa@gmail.com}
|
15
|
-
s.extra_rdoc_files = [
|
16
|
-
"LICENSE",
|
17
|
-
"README.rdoc"
|
18
|
-
]
|
19
|
-
s.files = [
|
20
|
-
".document",
|
21
|
-
".gitignore",
|
22
|
-
"LICENSE",
|
23
|
-
"README.rdoc",
|
24
|
-
"Rakefile",
|
25
|
-
"VERSION",
|
26
|
-
"lib/magic.rb",
|
27
|
-
"lib/magic/api.rb",
|
28
|
-
"lib/magic/constants.rb",
|
29
|
-
"lib/magic/database.rb",
|
30
|
-
"lib/magic/errors.rb",
|
31
|
-
"magic.gemspec",
|
32
|
-
"test/fixtures/filelogo.jpg",
|
33
|
-
"test/fixtures/magic.txt",
|
34
|
-
"test/fixtures/magic_empty",
|
35
|
-
"test/fixtures/magic_jpeg",
|
36
|
-
"test/helper.rb",
|
37
|
-
"test/test_magic.rb"
|
38
|
-
]
|
39
|
-
s.homepage = %q{http://github.com/qoobaa/magic}
|
40
|
-
s.post_install_message = %q{+-NOTE FOR LINUX USERS----------------------------------------------+
|
41
|
-
| |
|
42
|
-
| Install libmagic using your package manager, e.g. |
|
43
|
-
| |
|
44
|
-
| sudo apt-get install file |
|
45
|
-
| |
|
46
|
-
+-NOTE FOR WINDOWS USERS -------------------------------------------+
|
47
|
-
| |
|
48
|
-
| Install File for Windows from |
|
49
|
-
| |
|
50
|
-
| http://gnuwin32.sourceforge.net/packages/file.htm |
|
51
|
-
| |
|
52
|
-
| You'll also need to set your PATH environment variable to the |
|
53
|
-
| directory of the magic1.dll file |
|
54
|
-
| |
|
55
|
-
| set PATH=C:\Program Files\GnuWin32\bin;%PATH% |
|
56
|
-
| |
|
57
|
-
+-NOTE FOR MAC OS USERS --------------------------------------------+
|
58
|
-
| |
|
59
|
-
| If you don't have libmagic.1.dylib file in your system, you need |
|
60
|
-
| to install it using port command |
|
61
|
-
| |
|
62
|
-
| sudo port install file |
|
63
|
-
| |
|
64
|
-
+-------------------------------------------------------------------+
|
65
|
-
}
|
66
|
-
s.rdoc_options = ["--charset=UTF-8"]
|
67
|
-
s.require_paths = ["lib"]
|
68
|
-
s.rubygems_version = %q{1.3.5}
|
69
|
-
s.summary = %q{Determine file type and encoding using "magic" numbers}
|
70
|
-
s.test_files = [
|
71
|
-
"test/test_magic.rb",
|
72
|
-
"test/helper.rb"
|
73
|
-
]
|
74
|
-
|
75
|
-
if s.respond_to? :specification_version then
|
76
|
-
current_version = Gem::Specification::CURRENT_SPECIFICATION_VERSION
|
77
|
-
s.specification_version = 3
|
78
|
-
|
79
|
-
if Gem::Version.new(Gem::RubyGemsVersion) >= Gem::Version.new('1.2.0') then
|
80
|
-
s.add_runtime_dependency(%q<ffi>, [">= 0.6.0"])
|
81
|
-
s.add_development_dependency(%q<test-unit>, [">= 2.0"])
|
82
|
-
else
|
83
|
-
s.add_dependency(%q<ffi>, [">= 0.6.0"])
|
84
|
-
s.add_dependency(%q<test-unit>, [">= 2.0"])
|
85
|
-
end
|
86
|
-
else
|
87
|
-
s.add_dependency(%q<ffi>, [">= 0.6.0"])
|
88
|
-
s.add_dependency(%q<test-unit>, [">= 2.0"])
|
89
|
-
end
|
90
|
-
end
|
91
|
-
|
data/test/fixtures/filelogo.jpg
DELETED
Binary file
|
data/test/fixtures/magic.txt
DELETED
@@ -1 +0,0 @@
|
|
1
|
-
Magic® File™
|
data/test/fixtures/magic_empty
DELETED
@@ -1 +0,0 @@
|
|
1
|
-
# This is an empty magic database file
|
data/test/fixtures/magic_jpeg
DELETED
@@ -1,29 +0,0 @@
|
|
1
|
-
#------------------------------------------------------------------------------
|
2
|
-
# JPEG images
|
3
|
-
# SunOS 5.5.1 had
|
4
|
-
#
|
5
|
-
# 0 string \377\330\377\340 JPEG file
|
6
|
-
# 0 string \377\330\377\356 JPG file
|
7
|
-
#
|
8
|
-
# both of which turn into "JPEG image data" here.
|
9
|
-
#
|
10
|
-
0 beshort 0xffd8 JPEG image data
|
11
|
-
!:mime image/jpeg
|
12
|
-
!:apple 8BIMJPEG
|
13
|
-
!:strength +1
|
14
|
-
>6 string JFIF \b, JFIF standard
|
15
|
-
# The following added by Erik Rossen <rossen@freesurf.ch> 1999-09-06
|
16
|
-
# in a vain attempt to add image size reporting for JFIF. Note that these
|
17
|
-
# tests are not fool-proof since some perfectly valid JPEGs are currently
|
18
|
-
# impossible to specify in magic(4) format.
|
19
|
-
# First, a little JFIF version info:
|
20
|
-
>>11 byte x \b %d.
|
21
|
-
>>12 byte x \b%02d
|
22
|
-
# Next, the resolution or aspect ratio of the image:
|
23
|
-
#>>13 byte 0 \b, aspect ratio
|
24
|
-
#>>13 byte 1 \b, resolution (DPI)
|
25
|
-
#>>13 byte 2 \b, resolution (DPCM)
|
26
|
-
#>>4 beshort x \b, segment length %d
|
27
|
-
# Next, show thumbnail info, if it exists:
|
28
|
-
>>18 byte !0 \b, thumbnail %dx
|
29
|
-
>>>19 byte x \b%d
|
data/test/helper.rb
DELETED
@@ -1,13 +0,0 @@
|
|
1
|
-
require 'rubygems'
|
2
|
-
gem "test-unit"
|
3
|
-
require "test/unit"
|
4
|
-
|
5
|
-
$LOAD_PATH.unshift(File.join(File.dirname(__FILE__), '..', 'lib'))
|
6
|
-
$LOAD_PATH.unshift(File.dirname(__FILE__))
|
7
|
-
require 'magic'
|
8
|
-
|
9
|
-
class Test::Unit::TestCase
|
10
|
-
def fixture(filename)
|
11
|
-
File.join(File.dirname(__FILE__), "fixtures", filename)
|
12
|
-
end
|
13
|
-
end
|
data/test/test_magic.rb
DELETED
@@ -1,47 +0,0 @@
|
|
1
|
-
require 'helper'
|
2
|
-
|
3
|
-
class TestMagic < Test::Unit::TestCase
|
4
|
-
test "guess magic.txt mime" do
|
5
|
-
assert_equal "text/plain; charset=utf-8", Magic.guess_file_mime(fixture("magic.txt"))
|
6
|
-
end
|
7
|
-
|
8
|
-
test "guess magic.txt mime type" do
|
9
|
-
assert_equal "text/plain", Magic.guess_file_mime_type(fixture("magic.txt"))
|
10
|
-
end
|
11
|
-
|
12
|
-
test "guess magic.txt mime encoding" do
|
13
|
-
assert_equal "utf-8", Magic.guess_file_mime_encoding(fixture("magic.txt"))
|
14
|
-
end
|
15
|
-
|
16
|
-
test "guess filelogo.jpg mime" do
|
17
|
-
assert_equal "image/jpeg; charset=binary", Magic.guess_file_mime(fixture("filelogo.jpg"))
|
18
|
-
end
|
19
|
-
|
20
|
-
test "guess filelogo.jpg mime type" do
|
21
|
-
assert_equal "image/jpeg", Magic.guess_file_mime_type(fixture("filelogo.jpg"))
|
22
|
-
end
|
23
|
-
|
24
|
-
test "guess filelogo.jpg mime encoding" do
|
25
|
-
assert_equal "binary", Magic.guess_file_mime_encoding(fixture("filelogo.jpg"))
|
26
|
-
end
|
27
|
-
|
28
|
-
test "guess non-existing file mime" do
|
29
|
-
assert_raises Magic::Exception do
|
30
|
-
Magic.guess_file_mime(fixture("non-existing.file"))
|
31
|
-
end
|
32
|
-
end
|
33
|
-
|
34
|
-
test "guess filelogo.jpg mime with magic_jpeg database" do
|
35
|
-
assert_equal "image/jpeg; charset=binary", Magic.guess_file_mime(fixture("filelogo.jpg"), :database => fixture("magic_jpeg"))
|
36
|
-
end
|
37
|
-
|
38
|
-
test "guess filelogo.jpg mime with empty database" do
|
39
|
-
assert_equal "application/octet-stream; charset=binary", Magic.guess_file_mime(fixture("filelogo.jpg"), :database => fixture("magic_empty"))
|
40
|
-
end
|
41
|
-
|
42
|
-
test "guess with block" do
|
43
|
-
result = nil
|
44
|
-
Magic.guess(:mime) { |db| result = db.file(fixture("filelogo.jpg")) }
|
45
|
-
assert_equal "image/jpeg; charset=binary", result
|
46
|
-
end
|
47
|
-
end
|