ffi-magic 2011.04 → 2011.04.22
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.md +18 -8
- data/doc/AUTHORS +1 -1
- data/doc/CHANGELOG +16 -0
- data/ffi-magic.gemspec +1 -1
- data/lib/ffi-magic.rb +10 -10
- data/lib/ffi-magic/version.rb +1 -1
- data/spec/ffi-magic.rb +2 -2
- metadata +2 -1
data/README.md
CHANGED
@@ -2,11 +2,21 @@
|
|
2
2
|
|
3
3
|
## Usage
|
4
4
|
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
5
|
+
```ruby
|
6
|
+
require 'ffi-magic'
|
7
|
+
magic = Magic.new
|
8
|
+
magic.file('spec/magic.png')
|
9
|
+
# => "PNG image data, 100 x 67, 8-bit/color RGB, non-interlaced"
|
10
|
+
magic.flags = Magic::MIME
|
11
|
+
# => 1040
|
12
|
+
magic.file('spec/magic.png')
|
13
|
+
# => "image/png; charset=binary"
|
14
|
+
```
|
15
|
+
|
16
|
+
### Getting the MIME Type
|
17
|
+
|
18
|
+
```ruby
|
19
|
+
magic = Magic.new(Magic::MIME)
|
20
|
+
magic.file('spec/magic.png')
|
21
|
+
# => "image/png"
|
22
|
+
```
|
data/doc/AUTHORS
CHANGED
data/doc/CHANGELOG
CHANGED
@@ -1,3 +1,19 @@
|
|
1
|
+
[9d387d0 | Fri Apr 22 03:03:02 UTC 2011] Michael Fellinger <m.fellinger@gmail.com>
|
2
|
+
|
3
|
+
* Version 2011.04.22
|
4
|
+
|
5
|
+
[faba9e5 | Fri Apr 22 03:02:49 UTC 2011] Michael Fellinger <m.fellinger@gmail.com>
|
6
|
+
|
7
|
+
* Fix bug in Magic#buffer, makes specs pass
|
8
|
+
|
9
|
+
[e2e046a | Fri Apr 22 02:41:48 UTC 2011] Michael Fellinger <m.fellinger@gmail.com>
|
10
|
+
|
11
|
+
* clean up
|
12
|
+
|
13
|
+
[6ccf92e | Fri Apr 22 02:41:41 UTC 2011] Michael Fellinger <m.fellinger@gmail.com>
|
14
|
+
|
15
|
+
* Point out that you can pass the flag to Magic.new
|
16
|
+
|
1
17
|
[5a53006 | Fri Apr 22 02:04:14 UTC 2011] Michael Fellinger <m.fellinger@gmail.com>
|
2
18
|
|
3
19
|
* Version 2011.04
|
data/ffi-magic.gemspec
CHANGED
data/lib/ffi-magic.rb
CHANGED
@@ -6,15 +6,15 @@ class Magic
|
|
6
6
|
extend FFI::Library
|
7
7
|
ffi_lib ['magic', 'libmagic.so.1']
|
8
8
|
|
9
|
-
attach_function :magic_open,
|
10
|
-
attach_function :magic_error,
|
11
|
-
attach_function :magic_load,
|
12
|
-
attach_function :magic_file,
|
13
|
-
attach_function :magic_setflags, [:pointer, :int],
|
14
|
-
attach_function :magic_buffer,
|
15
|
-
attach_function :magic_check,
|
16
|
-
attach_function :magic_compile,
|
17
|
-
attach_function :magic_close,
|
9
|
+
attach_function :magic_open, [:int], :pointer
|
10
|
+
attach_function :magic_error, [:pointer], :string
|
11
|
+
attach_function :magic_load, [:pointer, :string], :int
|
12
|
+
attach_function :magic_file, [:pointer, :string], :string
|
13
|
+
attach_function :magic_setflags, [:pointer, :int], :void
|
14
|
+
attach_function :magic_buffer, [:pointer, :pointer, :int], :string
|
15
|
+
attach_function :magic_check, [:pointer, :string], :int
|
16
|
+
attach_function :magic_compile, [:pointer, :string], :int
|
17
|
+
attach_function :magic_close, [:pointer], :void
|
18
18
|
|
19
19
|
NONE = 0x000000
|
20
20
|
DEBUG = 0x000001
|
@@ -82,7 +82,7 @@ class Magic
|
|
82
82
|
|
83
83
|
def buffer(input)
|
84
84
|
input.force_encoding(Encoding::BINARY)
|
85
|
-
magic_buffer(@cookie, input, input.bytesize
|
85
|
+
magic_buffer(@cookie, input, input.bytesize)
|
86
86
|
end
|
87
87
|
|
88
88
|
def flags=(flags)
|
data/lib/ffi-magic/version.rb
CHANGED
data/spec/ffi-magic.rb
CHANGED
@@ -20,12 +20,12 @@ describe 'Magic' do
|
|
20
20
|
|
21
21
|
should 'buffer' do
|
22
22
|
@m.flags = Magic::NONE
|
23
|
-
@m.buffer(File.read(file)).should == "
|
23
|
+
@m.buffer(File.read(file)).should == "PNG image data, 100 x 67, 8-bit/color RGB, non-interlaced"
|
24
24
|
end
|
25
25
|
|
26
26
|
should 'buffer MIME' do
|
27
27
|
@m.flags = Magic::MIME
|
28
|
-
@m.buffer(File.read(file)).should == "
|
28
|
+
@m.buffer(File.read(file)).should == "image/png; charset=binary"
|
29
29
|
end
|
30
30
|
|
31
31
|
should 'have a valid database' do
|