magic 0.2.6 → 0.2.7

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 919960b329ad47db4dcb6da5974f285dd143c78e
4
+ data.tar.gz: 0148ea45766514a784595db16e0f6c4164946942
5
+ SHA512:
6
+ metadata.gz: b102fff10f1ae47bce7b37b0cf4abb6f3e59d0b676dc93f095843ffb37317a8854a8286e60670b4ef3c4e423f15642161cb88bd346b54806bf9fff44c8c8a24a
7
+ data.tar.gz: 2ee1c69e1ea2424c14da32606b5f02e146e155a6826d9cf34b60e428a58fbc5afb72e1e96c35e67f5da68d60cc5b4febb2452ed30228f3005499e0cdd23ede60
data/.gitignore ADDED
@@ -0,0 +1,17 @@
1
+ *.gem
2
+ *.rbc
3
+ .bundle
4
+ .config
5
+ .yardoc
6
+ Gemfile.lock
7
+ InstalledFiles
8
+ _yardoc
9
+ coverage
10
+ doc/
11
+ lib/bundler/man
12
+ pkg
13
+ rdoc
14
+ spec/reports
15
+ test/tmp
16
+ test/version_tmp
17
+ tmp
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in magic.gemspec
4
+ gemspec
@@ -1,4 +1,4 @@
1
- Copyright (c) 2010 Jakub Kuźma
1
+ Copyright (c) 2014 Kuba Kuźma
2
2
 
3
3
  Permission is hereby granted, free of charge, to any person obtaining
4
4
  a copy of this software and associated documentation files (the
data/Rakefile ADDED
@@ -0,0 +1,29 @@
1
+ $:.unshift File.expand_path("../lib", __FILE__)
2
+
3
+ require "rubygems"
4
+ require "rubygems/specification"
5
+ require "rake/testtask"
6
+ require "rdoc/task"
7
+ require "rubygems/package_task"
8
+ require "bundler/gem_tasks"
9
+ require "magic"
10
+
11
+ def gemspec
12
+ file = File.expand_path("../magic.gemspec", __FILE__)
13
+ eval(File.read(file), binding, file)
14
+ end
15
+
16
+ Rake::TestTask.new(:test) do |test|
17
+ test.libs << "lib" << "test"
18
+ test.pattern = "test/**/test_*.rb"
19
+ test.verbose = true
20
+ end
21
+
22
+ RDoc::Task.new do |rdoc|
23
+ rdoc.rdoc_dir = "rdoc"
24
+ rdoc.title = "magic #{Magic::VERSION}"
25
+ rdoc.rdoc_files.include("README.rdoc")
26
+ rdoc.rdoc_files.include("lib/**/*.rb")
27
+ end
28
+
29
+ task :default => :test
data/lib/magic.rb CHANGED
@@ -52,7 +52,7 @@ module Magic
52
52
  # Magic.guess_string_mime_encoding("Magic® File™")
53
53
  # # => "utf-8"
54
54
  def guess_string_mime_encoding(string, *args)
55
- guess(*args.unshift(:mime_type)) { |db| db.buffer(string) }
55
+ guess(*args.unshift(:mime_encoding)) { |db| db.buffer(string) }
56
56
  end
57
57
 
58
58
  # Guesses mime type of given string
@@ -29,6 +29,9 @@ module Magic
29
29
 
30
30
  # Determine type of a file at given path
31
31
  def file(filename)
32
+ if !File.exists?(filename)
33
+ raise Exception, "#{filename}: No such file or directory"
34
+ end
32
35
  result = Api.magic_file(@magic_set, filename.to_s)
33
36
  if result.null?
34
37
  raise Exception, error
data/lib/magic/version.rb CHANGED
@@ -1,3 +1,3 @@
1
1
  module Magic
2
- VERSION = "0.2.6"
2
+ VERSION = "0.2.7"
3
3
  end
data/magic.gemspec ADDED
@@ -0,0 +1,53 @@
1
+ # coding: utf-8
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require 'magic/version'
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = "magic"
8
+ spec.version = Magic::VERSION
9
+ spec.authors = ["Kuba Kuźma"]
10
+ spec.email = ["kuba@jah.pl"]
11
+ spec.summary = %q{Determine file type and encoding using "magic" numbers}
12
+ spec.description = %q{Ruby FFI bindings to libmagic}
13
+ spec.homepage = "https://github.com/qoobaa/magic"
14
+ spec.license = "MIT"
15
+
16
+ spec.files = `git ls-files -z`.split("\x0")
17
+ spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
18
+ spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
19
+ spec.require_paths = ["lib"]
20
+
21
+ spec.add_runtime_dependency "ffi", [">= 0.6.3"]
22
+ spec.add_development_dependency "bundler", "~> 1.5"
23
+ spec.add_development_dependency "rake"
24
+ spec.add_development_dependency "test-unit", [">= 2.0"]
25
+
26
+ spec.post_install_message = <<-EOM
27
+ +-NOTE FOR LINUX USERS----------------------------------------------+
28
+ | |
29
+ | Install libmagic using your package manager, e.g. |
30
+ | |
31
+ | sudo apt-get install file |
32
+ | |
33
+ +-NOTE FOR WINDOWS USERS -------------------------------------------+
34
+ | |
35
+ | Install File for Windows from |
36
+ | |
37
+ | http://gnuwin32.sourceforge.net/packages/file.htm |
38
+ | |
39
+ | You'll also need to set your PATH environment variable to the |
40
+ | directory of the magic1.dll file |
41
+ | |
42
+ | set PATH=C:\\Program Files\\GnuWin32\\bin;%PATH% |
43
+ | |
44
+ +-NOTE FOR MAC OS USERS --------------------------------------------+
45
+ | |
46
+ | If you don't have libmagic.1.dylib file in your system, you need |
47
+ | to install it using port command |
48
+ | |
49
+ | sudo port install file |
50
+ | |
51
+ +-------------------------------------------------------------------+
52
+ EOM
53
+ end
Binary file
@@ -0,0 +1 @@
1
+ Magic® File™
@@ -0,0 +1 @@
1
+ # This is an empty magic database file
@@ -0,0 +1,29 @@
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 ADDED
@@ -0,0 +1,13 @@
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
@@ -0,0 +1,54 @@
1
+ # encoding: UTF-8
2
+
3
+ require "helper"
4
+
5
+ class TestMagic < Test::Unit::TestCase
6
+ test "guess magic.txt mime" do
7
+ assert_equal "text/plain; charset=utf-8", Magic.guess_file_mime(fixture("magic.txt"))
8
+ end
9
+
10
+ test "guess magic.txt mime type" do
11
+ assert_equal "text/plain", Magic.guess_file_mime_type(fixture("magic.txt"))
12
+ end
13
+
14
+ test "guess magic.txt mime encoding" do
15
+ assert_equal "utf-8", Magic.guess_file_mime_encoding(fixture("magic.txt"))
16
+ end
17
+
18
+ test "guess filelogo.jpg mime" do
19
+ assert_equal "image/jpeg; charset=binary", Magic.guess_file_mime(fixture("filelogo.jpg"))
20
+ end
21
+
22
+ test "guess filelogo.jpg mime type" do
23
+ assert_equal "image/jpeg", Magic.guess_file_mime_type(fixture("filelogo.jpg"))
24
+ end
25
+
26
+ test "guess filelogo.jpg mime encoding" do
27
+ assert_equal "binary", Magic.guess_file_mime_encoding(fixture("filelogo.jpg"))
28
+ end
29
+
30
+ test "guess non-existing file mime" do
31
+ assert_raises Magic::Exception do
32
+ Magic.guess_file_mime(fixture("non-existing.file"))
33
+ end
34
+ end
35
+
36
+ test "guess filelogo.jpg mime with magic_jpeg database" do
37
+ assert_equal "image/jpeg; charset=binary", Magic.guess_file_mime(fixture("filelogo.jpg"), :database => fixture("magic_jpeg"))
38
+ end
39
+
40
+ test "guess filelogo.jpg mime with empty database" do
41
+ assert_equal "application/octet-stream; charset=binary", Magic.guess_file_mime(fixture("filelogo.jpg"), :database => fixture("magic_empty"))
42
+ end
43
+
44
+ test "guess with block" do
45
+ result = nil
46
+ Magic.guess(:mime) { |db| result = db.file(fixture("filelogo.jpg")) }
47
+ assert_equal "image/jpeg; charset=binary", result
48
+ end
49
+
50
+ test "guess encoding from string" do
51
+ utf8 = "utf-8".force_encoding(Encoding::ASCII_8BIT)
52
+ assert_equal utf8, Magic.guess_string_mime_encoding('áéíóú')
53
+ end
54
+ end
metadata CHANGED
@@ -1,75 +1,100 @@
1
- --- !ruby/object:Gem::Specification
1
+ --- !ruby/object:Gem::Specification
2
2
  name: magic
3
- version: !ruby/object:Gem::Version
4
- hash: 27
5
- prerelease: false
6
- segments:
7
- - 0
8
- - 2
9
- - 6
10
- version: 0.2.6
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.2.7
11
5
  platform: ruby
12
- authors:
13
- - "Jakub Ku\xC5\xBAma"
6
+ authors:
7
+ - Kuba Kuźma
14
8
  autorequire:
15
9
  bindir: bin
16
10
  cert_chain: []
17
-
18
- date: 2010-06-13 00:00:00 +02:00
19
- default_executable:
20
- dependencies:
21
- - !ruby/object:Gem::Dependency
11
+ date: 2014-04-22 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
22
14
  name: ffi
23
- prerelease: false
24
- requirement: &id001 !ruby/object:Gem::Requirement
25
- none: false
26
- requirements:
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
27
17
  - - ">="
28
- - !ruby/object:Gem::Version
29
- hash: 1
30
- segments:
31
- - 0
32
- - 6
33
- - 3
18
+ - !ruby/object:Gem::Version
34
19
  version: 0.6.3
35
20
  type: :runtime
36
- version_requirements: *id001
37
- - !ruby/object:Gem::Dependency
38
- name: test-unit
39
21
  prerelease: false
40
- requirement: &id002 !ruby/object:Gem::Requirement
41
- none: false
42
- requirements:
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - ">="
25
+ - !ruby/object:Gem::Version
26
+ version: 0.6.3
27
+ - !ruby/object:Gem::Dependency
28
+ name: bundler
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - "~>"
32
+ - !ruby/object:Gem::Version
33
+ version: '1.5'
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - "~>"
39
+ - !ruby/object:Gem::Version
40
+ version: '1.5'
41
+ - !ruby/object:Gem::Dependency
42
+ name: rake
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - ">="
46
+ - !ruby/object:Gem::Version
47
+ version: '0'
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
43
52
  - - ">="
44
- - !ruby/object:Gem::Version
45
- hash: 3
46
- segments:
47
- - 2
48
- - 0
49
- version: "2.0"
53
+ - !ruby/object:Gem::Version
54
+ version: '0'
55
+ - !ruby/object:Gem::Dependency
56
+ name: test-unit
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - ">="
60
+ - !ruby/object:Gem::Version
61
+ version: '2.0'
50
62
  type: :development
51
- version_requirements: *id002
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - ">="
67
+ - !ruby/object:Gem::Version
68
+ version: '2.0'
52
69
  description: Ruby FFI bindings to libmagic
53
- email: qoobaa@gmail.com
70
+ email:
71
+ - kuba@jah.pl
54
72
  executables: []
55
-
56
73
  extensions: []
57
-
58
74
  extra_rdoc_files: []
59
-
60
- files:
75
+ files:
76
+ - ".gitignore"
77
+ - Gemfile
78
+ - LICENSE.txt
79
+ - README.rdoc
80
+ - Rakefile
61
81
  - lib/magic.rb
62
82
  - lib/magic/api.rb
63
- - lib/magic/database.rb
64
83
  - lib/magic/constants.rb
65
- - lib/magic/version.rb
84
+ - lib/magic/database.rb
66
85
  - lib/magic/errors.rb
67
- - LICENSE
68
- - README.rdoc
69
- has_rdoc: true
70
- homepage: http://jah.pl/projects/magic.html
71
- licenses: []
72
-
86
+ - lib/magic/version.rb
87
+ - magic.gemspec
88
+ - test/fixtures/filelogo.jpg
89
+ - test/fixtures/magic.txt
90
+ - test/fixtures/magic_empty
91
+ - test/fixtures/magic_jpeg
92
+ - test/helper.rb
93
+ - test/test_magic.rb
94
+ homepage: https://github.com/qoobaa/magic
95
+ licenses:
96
+ - MIT
97
+ metadata: {}
73
98
  post_install_message: |
74
99
  +-NOTE FOR LINUX USERS----------------------------------------------+
75
100
  | |
@@ -96,37 +121,29 @@ post_install_message: |
96
121
  | sudo port install file |
97
122
  | |
98
123
  +-------------------------------------------------------------------+
99
-
100
124
  rdoc_options: []
101
-
102
- require_paths:
125
+ require_paths:
103
126
  - lib
104
- required_ruby_version: !ruby/object:Gem::Requirement
105
- none: false
106
- requirements:
127
+ required_ruby_version: !ruby/object:Gem::Requirement
128
+ requirements:
107
129
  - - ">="
108
- - !ruby/object:Gem::Version
109
- hash: 3
110
- segments:
111
- - 0
112
- version: "0"
113
- required_rubygems_version: !ruby/object:Gem::Requirement
114
- none: false
115
- requirements:
130
+ - !ruby/object:Gem::Version
131
+ version: '0'
132
+ required_rubygems_version: !ruby/object:Gem::Requirement
133
+ requirements:
116
134
  - - ">="
117
- - !ruby/object:Gem::Version
118
- hash: 23
119
- segments:
120
- - 1
121
- - 3
122
- - 6
123
- version: 1.3.6
135
+ - !ruby/object:Gem::Version
136
+ version: '0'
124
137
  requirements: []
125
-
126
138
  rubyforge_project:
127
- rubygems_version: 1.3.7
139
+ rubygems_version: 2.2.0
128
140
  signing_key:
129
- specification_version: 3
141
+ specification_version: 4
130
142
  summary: Determine file type and encoding using "magic" numbers
131
- test_files: []
132
-
143
+ test_files:
144
+ - test/fixtures/filelogo.jpg
145
+ - test/fixtures/magic.txt
146
+ - test/fixtures/magic_empty
147
+ - test/fixtures/magic_jpeg
148
+ - test/helper.rb
149
+ - test/test_magic.rb