ffi-extractor 0.1.0
Sign up to get free protection for your applications and to get access to all the features.
- data/.document +3 -0
- data/.gitignore +2 -0
- data/.rspec +1 -0
- data/.yardopts +1 -0
- data/COPYING.txt +339 -0
- data/ChangeLog.md +4 -0
- data/README.md +66 -0
- data/Rakefile +40 -0
- data/ffi-extractor.gemspec +60 -0
- data/gemspec.yml +20 -0
- data/lib/ffi/extractor/extractor.rb +110 -0
- data/lib/ffi/extractor/library.rb +44 -0
- data/lib/ffi/extractor/metadata_processor.rb +77 -0
- data/lib/ffi/extractor/plugin_list.rb +153 -0
- data/lib/ffi/extractor/types.rb +257 -0
- data/lib/ffi/extractor/version.rb +26 -0
- data/lib/ffi/extractor.rb +23 -0
- data/spec/extractor_spec.rb +45 -0
- data/spec/files/image.jpg +0 -0
- data/spec/files/image.meta +1166 -0
- data/spec/metadata_processor_spec.rb +90 -0
- data/spec/plugin_list_spec.rb +74 -0
- data/spec/spec_helper.rb +5 -0
- metadata +137 -0
@@ -0,0 +1,90 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
require 'ffi/extractor/metadata_processor'
|
3
|
+
|
4
|
+
describe MetadataProcessor do
|
5
|
+
let(:plugin_name) { :pdf }
|
6
|
+
let(:plugin) { "/usr/lib/libextractor/libextractor_#{plugin_name}.so" }
|
7
|
+
let(:type) { :format }
|
8
|
+
let(:format) { :utf8 }
|
9
|
+
let(:mime_type) { 'text/plain' }
|
10
|
+
let(:data) { 'PDF 1.5' }
|
11
|
+
let(:size) { data.length }
|
12
|
+
|
13
|
+
let(:buffer) do
|
14
|
+
FFI::Buffer.new(size + 1).tap do |buffer|
|
15
|
+
buffer.put_bytes(0,data)
|
16
|
+
end
|
17
|
+
end
|
18
|
+
|
19
|
+
subject do
|
20
|
+
processor = described_class.new do |plugin_name,type,format,mime_type,data|
|
21
|
+
@yielded_plugin_name = plugin_name
|
22
|
+
@yielded_type = type
|
23
|
+
@yielded_format = format
|
24
|
+
@yielded_mime_type = mime_type
|
25
|
+
@yielded_data = data
|
26
|
+
end
|
27
|
+
end
|
28
|
+
|
29
|
+
before { subject.call(nil,plugin,type,format,mime_type,buffer,size) }
|
30
|
+
|
31
|
+
describe "yielded arguments" do
|
32
|
+
it "should map plugin paths to names" do
|
33
|
+
@yielded_plugin_name.should == plugin_name
|
34
|
+
end
|
35
|
+
|
36
|
+
it "should yield the type" do
|
37
|
+
@yielded_type.should == type
|
38
|
+
end
|
39
|
+
|
40
|
+
it "should yield the format" do
|
41
|
+
@yielded_format.should == format
|
42
|
+
end
|
43
|
+
|
44
|
+
it "should yield the mime-type" do
|
45
|
+
@yielded_mime_type.should == mime_type
|
46
|
+
end
|
47
|
+
|
48
|
+
describe "data" do
|
49
|
+
context "when passed binary" do
|
50
|
+
before { subject.call(nil,plugin,:binary,format,mime_type,buffer,size) }
|
51
|
+
|
52
|
+
it "should yield the bytes" do
|
53
|
+
@yielded_data.should == data
|
54
|
+
end
|
55
|
+
end
|
56
|
+
|
57
|
+
context "when passwd a c_string" do
|
58
|
+
before { subject.call(nil,plugin,:c_string,format,mime_type,buffer,size) }
|
59
|
+
|
60
|
+
it "should yield the string" do
|
61
|
+
@yielded_data.should == data
|
62
|
+
end
|
63
|
+
end
|
64
|
+
|
65
|
+
context "when passwd utf8" do
|
66
|
+
before { subject.call(nil,plugin,:utf8,format,mime_type,buffer,size) }
|
67
|
+
|
68
|
+
it "should yield the string" do
|
69
|
+
@yielded_data.should == data
|
70
|
+
end
|
71
|
+
end
|
72
|
+
end
|
73
|
+
end
|
74
|
+
|
75
|
+
it "should return 0 by default" do
|
76
|
+
subject.call(nil,plugin,type,format,mime_type,buffer,size).should == 0
|
77
|
+
end
|
78
|
+
|
79
|
+
context "when :return is thrown" do
|
80
|
+
subject do
|
81
|
+
described_class.new do |plugin_name,type,format,mime_type,data|
|
82
|
+
throw :return, 1
|
83
|
+
end
|
84
|
+
end
|
85
|
+
|
86
|
+
it "should catch :abort" do
|
87
|
+
subject.call(nil,plugin,type,format,mime_type,buffer,size).should == 1
|
88
|
+
end
|
89
|
+
end
|
90
|
+
end
|
@@ -0,0 +1,74 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
require 'ffi/extractor/plugin_list'
|
3
|
+
|
4
|
+
describe PluginList do
|
5
|
+
let(:plugin) { :mp3 }
|
6
|
+
|
7
|
+
describe "default" do
|
8
|
+
it "should load the default plugins" do
|
9
|
+
lambda {
|
10
|
+
described_class.default
|
11
|
+
}.should_not raise_error(LoadError)
|
12
|
+
end
|
13
|
+
|
14
|
+
context "when no plugins could be loaded" do
|
15
|
+
before { ENV['LIBEXTRACTOR_LIBRARIES'] = '/does/not/exist' }
|
16
|
+
|
17
|
+
it "should raise LoadError" do
|
18
|
+
lambda {
|
19
|
+
described_class.default
|
20
|
+
}.should raise_error(LoadError)
|
21
|
+
end
|
22
|
+
|
23
|
+
after { ENV.delete('LIBEXTRACTOR_LIBRARIES') }
|
24
|
+
end
|
25
|
+
end
|
26
|
+
|
27
|
+
describe "#add" do
|
28
|
+
it "should load an individual plugin" do
|
29
|
+
subject.add(plugin)
|
30
|
+
|
31
|
+
subject.to_ptr.should_not be_nil
|
32
|
+
end
|
33
|
+
|
34
|
+
context "when given an invalid plugin name" do
|
35
|
+
it "should raise LoadError" do
|
36
|
+
lambda {
|
37
|
+
subject.add('foo')
|
38
|
+
}.should raise_error(LoadError)
|
39
|
+
end
|
40
|
+
end
|
41
|
+
end
|
42
|
+
|
43
|
+
describe "#remove" do
|
44
|
+
before { subject.add(plugin) }
|
45
|
+
|
46
|
+
it "should remove a plugin from the list" do
|
47
|
+
subject.remove(plugin)
|
48
|
+
end
|
49
|
+
|
50
|
+
context "when given an plugin name not in the list" do
|
51
|
+
it "should raise LoadError" do
|
52
|
+
lambda {
|
53
|
+
subject.remove('foo')
|
54
|
+
}.should raise_error(ArgumentError)
|
55
|
+
end
|
56
|
+
end
|
57
|
+
end
|
58
|
+
|
59
|
+
describe "#remove_all" do
|
60
|
+
context "when the plugin list is not empty" do
|
61
|
+
before { subject.add(plugin) }
|
62
|
+
|
63
|
+
it "should remove all plugins in the list" do
|
64
|
+
subject.remove_all
|
65
|
+
end
|
66
|
+
end
|
67
|
+
|
68
|
+
context "when the plugin list is empty" do
|
69
|
+
it "should no-op" do
|
70
|
+
subject.remove_all
|
71
|
+
end
|
72
|
+
end
|
73
|
+
end
|
74
|
+
end
|
data/spec/spec_helper.rb
ADDED
metadata
ADDED
@@ -0,0 +1,137 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: ffi-extractor
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.1.0
|
5
|
+
prerelease:
|
6
|
+
platform: ruby
|
7
|
+
authors:
|
8
|
+
- Postmodern
|
9
|
+
autorequire:
|
10
|
+
bindir: bin
|
11
|
+
cert_chain: []
|
12
|
+
date: 2012-08-12 00:00:00.000000000 Z
|
13
|
+
dependencies:
|
14
|
+
- !ruby/object:Gem::Dependency
|
15
|
+
name: ffi
|
16
|
+
requirement: !ruby/object:Gem::Requirement
|
17
|
+
none: false
|
18
|
+
requirements:
|
19
|
+
- - ~>
|
20
|
+
- !ruby/object:Gem::Version
|
21
|
+
version: '1.0'
|
22
|
+
type: :runtime
|
23
|
+
prerelease: false
|
24
|
+
version_requirements: !ruby/object:Gem::Requirement
|
25
|
+
none: false
|
26
|
+
requirements:
|
27
|
+
- - ~>
|
28
|
+
- !ruby/object:Gem::Version
|
29
|
+
version: '1.0'
|
30
|
+
- !ruby/object:Gem::Dependency
|
31
|
+
name: rspec
|
32
|
+
requirement: !ruby/object:Gem::Requirement
|
33
|
+
none: false
|
34
|
+
requirements:
|
35
|
+
- - ~>
|
36
|
+
- !ruby/object:Gem::Version
|
37
|
+
version: '2.4'
|
38
|
+
type: :development
|
39
|
+
prerelease: false
|
40
|
+
version_requirements: !ruby/object:Gem::Requirement
|
41
|
+
none: false
|
42
|
+
requirements:
|
43
|
+
- - ~>
|
44
|
+
- !ruby/object:Gem::Version
|
45
|
+
version: '2.4'
|
46
|
+
- !ruby/object:Gem::Dependency
|
47
|
+
name: rubygems-tasks
|
48
|
+
requirement: !ruby/object:Gem::Requirement
|
49
|
+
none: false
|
50
|
+
requirements:
|
51
|
+
- - ~>
|
52
|
+
- !ruby/object:Gem::Version
|
53
|
+
version: '0.2'
|
54
|
+
type: :development
|
55
|
+
prerelease: false
|
56
|
+
version_requirements: !ruby/object:Gem::Requirement
|
57
|
+
none: false
|
58
|
+
requirements:
|
59
|
+
- - ~>
|
60
|
+
- !ruby/object:Gem::Version
|
61
|
+
version: '0.2'
|
62
|
+
- !ruby/object:Gem::Dependency
|
63
|
+
name: yard
|
64
|
+
requirement: !ruby/object:Gem::Requirement
|
65
|
+
none: false
|
66
|
+
requirements:
|
67
|
+
- - ~>
|
68
|
+
- !ruby/object:Gem::Version
|
69
|
+
version: '0.8'
|
70
|
+
type: :development
|
71
|
+
prerelease: false
|
72
|
+
version_requirements: !ruby/object:Gem::Requirement
|
73
|
+
none: false
|
74
|
+
requirements:
|
75
|
+
- - ~>
|
76
|
+
- !ruby/object:Gem::Version
|
77
|
+
version: '0.8'
|
78
|
+
description: Ruby FFI bindings to libextractor, a library for extracting metadata
|
79
|
+
from a variety of file formats.
|
80
|
+
email: postmodern.mod3@gmail.com
|
81
|
+
executables: []
|
82
|
+
extensions: []
|
83
|
+
extra_rdoc_files:
|
84
|
+
- COPYING.txt
|
85
|
+
- ChangeLog.md
|
86
|
+
- README.md
|
87
|
+
files:
|
88
|
+
- .document
|
89
|
+
- .gitignore
|
90
|
+
- .rspec
|
91
|
+
- .yardopts
|
92
|
+
- COPYING.txt
|
93
|
+
- ChangeLog.md
|
94
|
+
- README.md
|
95
|
+
- Rakefile
|
96
|
+
- ffi-extractor.gemspec
|
97
|
+
- gemspec.yml
|
98
|
+
- lib/ffi/extractor.rb
|
99
|
+
- lib/ffi/extractor/extractor.rb
|
100
|
+
- lib/ffi/extractor/library.rb
|
101
|
+
- lib/ffi/extractor/metadata_processor.rb
|
102
|
+
- lib/ffi/extractor/plugin_list.rb
|
103
|
+
- lib/ffi/extractor/types.rb
|
104
|
+
- lib/ffi/extractor/version.rb
|
105
|
+
- spec/extractor_spec.rb
|
106
|
+
- spec/files/image.jpg
|
107
|
+
- spec/files/image.meta
|
108
|
+
- spec/metadata_processor_spec.rb
|
109
|
+
- spec/plugin_list_spec.rb
|
110
|
+
- spec/spec_helper.rb
|
111
|
+
homepage: https://github.com/postmodern/ffi-extractor#readme
|
112
|
+
licenses:
|
113
|
+
- GPLv2
|
114
|
+
post_install_message:
|
115
|
+
rdoc_options: []
|
116
|
+
require_paths:
|
117
|
+
- lib
|
118
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
119
|
+
none: false
|
120
|
+
requirements:
|
121
|
+
- - ! '>='
|
122
|
+
- !ruby/object:Gem::Version
|
123
|
+
version: '0'
|
124
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
125
|
+
none: false
|
126
|
+
requirements:
|
127
|
+
- - ! '>='
|
128
|
+
- !ruby/object:Gem::Version
|
129
|
+
version: '0'
|
130
|
+
requirements:
|
131
|
+
- libextractor >= 0.6.0
|
132
|
+
rubyforge_project:
|
133
|
+
rubygems_version: 1.8.24
|
134
|
+
signing_key:
|
135
|
+
specification_version: 3
|
136
|
+
summary: Ruby FFI bindings to libextractor
|
137
|
+
test_files: []
|