file_classify 0.0.1 → 0.0.2
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.md +30 -1
- data/Rakefile +4 -0
- data/lib/file_classify.rb +2 -2
- data/lib/file_classify/version.rb +1 -1
- data/spec/lib/file_classify_spec.rb +8 -0
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 2602de0b80f2ba410f75037c3f1dc61dc0f2d929
|
4
|
+
data.tar.gz: b3cc1c0ea8bc32e78ec0475ad48f91411ef7868a
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 2ff5f2546327bfb490e2995d70e1162bef50a4129c5b918a4fe736c2a87d328da40c6cb778e50c5192912aa4541516a63c89cd3177e73e0852d65c161a3444dc
|
7
|
+
data.tar.gz: 04a5c55ea60d4a9a02630ec52e4df4634b49a7970cd45be257739c39b815edd76e0cd72733378eb6f9a7db38727e414098fbb484707e9a21f2f67ff129ae0394
|
data/README.md
CHANGED
@@ -2,6 +2,12 @@
|
|
2
2
|
|
3
3
|
Binary and ASCII classification for files
|
4
4
|
|
5
|
+
[![Gem Version](https://badge.fury.io/rb/file_classify.png)](http://badge.fury.io/rb/file_classify)
|
6
|
+
[![Build Status](https://travis-ci.org/rcaught/file_classify.png?branch=master)](https://travis-ci.org/rcaught/file_classify)
|
7
|
+
[![Dependency Status](https://gemnasium.com/rcaught/file_classify.png)](https://gemnasium.com/rcaught/file_classify)
|
8
|
+
[![Coverage Status](https://coveralls.io/repos/rcaught/file_classify/badge.png)](https://coveralls.io/r/rcaught/file_classify)
|
9
|
+
[![Code Climate](https://codeclimate.com/github/rcaught/file_classify.png)](https://codeclimate.com/github/rcaught/file_classify)
|
10
|
+
|
5
11
|
## Installation
|
6
12
|
|
7
13
|
Add this line to your application's Gemfile:
|
@@ -18,7 +24,30 @@ Or install it yourself as:
|
|
18
24
|
|
19
25
|
## Usage
|
20
26
|
|
21
|
-
|
27
|
+
```ruby
|
28
|
+
require 'file_classify'
|
29
|
+
|
30
|
+
classifier = FileClassify.new(path: 'spec/resources/binary.jpg')
|
31
|
+
=> #<FileClassify:0x007fbf04c31098 @contents=nil, @path="spec/resources/binary.jpg">
|
32
|
+
classifier.binary?
|
33
|
+
=> true
|
34
|
+
classifier.ascii?
|
35
|
+
=> false
|
36
|
+
classifier.classify
|
37
|
+
=> "binary"
|
38
|
+
|
39
|
+
|
40
|
+
# Or perhaps you have file contents?
|
41
|
+
|
42
|
+
classifier = FileClassify.new(contents: 'And miles to go before I sleep.')
|
43
|
+
=> #<FileClassify:0x007fbf04cd0ff8 @contents="And miles to go before I sleep.", @path=nil>
|
44
|
+
classifier.binary?
|
45
|
+
=> false
|
46
|
+
classifier.ascii?
|
47
|
+
=> true
|
48
|
+
classifier.classify
|
49
|
+
=> "ascii"
|
50
|
+
```
|
22
51
|
|
23
52
|
## Contributing
|
24
53
|
|
data/Rakefile
CHANGED
data/lib/file_classify.rb
CHANGED
@@ -17,8 +17,8 @@ class FileClassify
|
|
17
17
|
file_path = self.path
|
18
18
|
|
19
19
|
if self.contents
|
20
|
-
temp = Tempfile.new('block_size_check')
|
21
|
-
temp.write(self.contents)
|
20
|
+
temp = Tempfile.new('block_size_check', encoding: 'utf-8')
|
21
|
+
temp.write(self.contents.force_encoding('utf-8'))
|
22
22
|
temp.close
|
23
23
|
|
24
24
|
file_path = temp.path
|
@@ -9,6 +9,10 @@ describe FileClassify do
|
|
9
9
|
FileClassify.new(contents: File.read(BINARY_FILE))
|
10
10
|
end
|
11
11
|
|
12
|
+
let :binary_ascii_8bit_contents_subject do
|
13
|
+
FileClassify.new(contents: File.read(BINARY_FILE).force_encoding('ascii-8bit'))
|
14
|
+
end
|
15
|
+
|
12
16
|
let :binary_path_subject do
|
13
17
|
FileClassify.new(path: BINARY_FILE)
|
14
18
|
end
|
@@ -59,6 +63,10 @@ describe FileClassify do
|
|
59
63
|
ascii_contents_subject.binary?.should be_false
|
60
64
|
ascii_path_subject.binary?.should be_false
|
61
65
|
end
|
66
|
+
|
67
|
+
it 'handles ascii-8bit encoded content strings' do
|
68
|
+
binary_ascii_8bit_contents_subject.binary?.should be_true
|
69
|
+
end
|
62
70
|
end
|
63
71
|
|
64
72
|
context '#ascii?' do
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: file_classify
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.2
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Ryan Caught
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2013-08-
|
11
|
+
date: 2013-08-12 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|