assembly-objectfile 1.7.2 → 1.8.0
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.
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: fb34254f64779ebdf334f939519f151b6ffdf661588d194813efd2efa9e7d0fa
|
4
|
+
data.tar.gz: 98c7c49e243a5751002e68726f06665c210e7f360e10b08ef6f791abca3e00d9
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 367d8abe3505708082bf7473a47e808195b6b12010c99a8227acdee0763e801f3018491593ad9071662a1903097c39740ab7ef8dbf94a2e404fc7abeee2b31c4
|
7
|
+
data.tar.gz: 443d63aa3187774914f0f61e71536f8612afea82414ded40293138e63446da452581e0f4e4a11f945ead2f7019a9722dcd8d054fd1669e04d64c0586827796db
|
@@ -108,23 +108,26 @@ module Assembly
|
|
108
108
|
@sha1 ||= Digest::SHA1.file(path).hexdigest
|
109
109
|
end
|
110
110
|
|
111
|
-
# Returns mimetype information for the current file based on
|
111
|
+
# Returns mimetype information for the current file based on
|
112
|
+
# (1) exifdata (if available), (2) unix file type or (3) file extension using the mimetypes gem, in this priority order
|
112
113
|
# @return [String] mime type
|
113
114
|
# @example
|
114
115
|
# source_file = Assembly::ObjectFile.new('/input/path_to_file.txt')
|
115
116
|
# puts source_file.mimetype # 'text/plain'
|
116
117
|
def mimetype
|
117
118
|
@mimetype ||= begin
|
118
|
-
if
|
119
|
-
|
120
|
-
|
119
|
+
if exif_mimetype # first, try the exif data
|
120
|
+
exif_mimetype
|
121
|
+
elsif file_mimetype # next, try exif/unix file system command
|
122
|
+
file_mimetype
|
123
|
+
else # finally, get it from the mime-types gem (using the file extension) if both of those failed for some reason
|
121
124
|
mtype = MIME::Types.type_for(path).first
|
122
125
|
mtype ? mtype.content_type : ''
|
123
126
|
end
|
124
127
|
end
|
125
128
|
end
|
126
129
|
|
127
|
-
# Returns mimetype information for the current file based on unix file system command
|
130
|
+
# Returns mimetype information for the current file based on unix file system command.
|
128
131
|
# @return [String] mime type for supplied file
|
129
132
|
# @example
|
130
133
|
# source_file = Assembly::ObjectFile.new('/input/path_to_file.txt')
|
@@ -132,9 +135,20 @@ module Assembly
|
|
132
135
|
def file_mimetype
|
133
136
|
@file_mimetype ||= begin
|
134
137
|
check_for_file
|
135
|
-
|
136
|
-
|
137
|
-
|
138
|
+
`file --mime-type "#{path}"`.delete("\n").split(':')[1].strip # first try and get the mimetype from the unix file command
|
139
|
+
end
|
140
|
+
end
|
141
|
+
|
142
|
+
# Returns mimetype information for the current file based on exif data (if available and not a trusted source that we'd rather get from the file system command)
|
143
|
+
# @return [String] mime type for supplied file
|
144
|
+
# @example
|
145
|
+
# source_file = Assembly::ObjectFile.new('/input/path_to_file.txt')
|
146
|
+
# puts source_file.exif_mimetype # 'text/plain'
|
147
|
+
def exif_mimetype
|
148
|
+
@exif_mimetype ||= begin
|
149
|
+
check_for_file
|
150
|
+
prefer_exif = !Assembly::TRUSTED_MIMETYPES.include?(file_mimetype) # if it's not a "trusted" mimetype and there is exif data; get the mimetype from the exif
|
151
|
+
exif.mimetype if exif && exif.mimetype && prefer_exif
|
138
152
|
end
|
139
153
|
end
|
140
154
|
|
data/spec/object_file_spec.rb
CHANGED
@@ -36,6 +36,41 @@ describe Assembly::ObjectFile do
|
|
36
36
|
expect(@ai.dirname).to eq(File.dirname(TEST_TIF_INPUT_FILE))
|
37
37
|
end
|
38
38
|
|
39
|
+
it 'sets the correct mimetype of plain/text for .txt files' do
|
40
|
+
@ai = described_class.new(TEST_RES1_TEXT)
|
41
|
+
expect(@ai.mimetype).to eq('text/plain')
|
42
|
+
end
|
43
|
+
|
44
|
+
it 'sets the correct mimetype of plain/text for .xml files' do
|
45
|
+
@ai = described_class.new(TEST_RES1_TEXT)
|
46
|
+
expect(@ai.mimetype).to eq('text/plain')
|
47
|
+
end
|
48
|
+
|
49
|
+
it 'sets the correct mimetype of plain/text for .obj 3d files' do
|
50
|
+
@ai = described_class.new(TEST_OBJ_FILE)
|
51
|
+
expect(@ai.mimetype).to eq('text/plain')
|
52
|
+
end
|
53
|
+
|
54
|
+
it 'sets the correct mimetype of plain/text for .ply 3d files' do
|
55
|
+
@ai = described_class.new(TEST_PLY_FILE)
|
56
|
+
expect(@ai.mimetype).to eq('text/plain')
|
57
|
+
end
|
58
|
+
|
59
|
+
it 'sets the correct mimetype of image/tiff for .tif files' do
|
60
|
+
@ai = described_class.new(TEST_TIF_INPUT_FILE)
|
61
|
+
expect(@ai.mimetype).to eq('image/tiff')
|
62
|
+
end
|
63
|
+
|
64
|
+
it 'sets the correct mimetype of image/jp2 for .jp2 files' do
|
65
|
+
@ai = described_class.new(TEST_JP2_INPUT_FILE)
|
66
|
+
expect(@ai.mimetype).to eq('image/jp2')
|
67
|
+
end
|
68
|
+
|
69
|
+
it 'sets the correct mimetype of application/pdf for .pdf files' do
|
70
|
+
@ai = described_class.new(TEST_RES1_PDF)
|
71
|
+
expect(@ai.mimetype).to eq('application/pdf')
|
72
|
+
end
|
73
|
+
|
39
74
|
it 'gives us the mimetype of a file even if the exif information is damaged' do
|
40
75
|
@ai = described_class.new(TEST_FILE_NO_EXIF)
|
41
76
|
expect(@ai.filename).to eq('file_with_no_exif.xml')
|
@@ -141,7 +176,7 @@ describe Assembly::ObjectFile do
|
|
141
176
|
expect(File.exist?(non_image_file)).to be true
|
142
177
|
@ai = described_class.new(non_image_file)
|
143
178
|
expect(@ai.image?).to eq(false)
|
144
|
-
expect(@ai.object_type).
|
179
|
+
expect(@ai.object_type).not_to eq(:image)
|
145
180
|
expect(@ai.valid_image?).to eq(false)
|
146
181
|
end
|
147
182
|
|
Binary file
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: assembly-objectfile
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.
|
4
|
+
version: 1.8.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Peter Mangiafico
|
@@ -11,7 +11,7 @@ authors:
|
|
11
11
|
autorequire:
|
12
12
|
bindir: exe
|
13
13
|
cert_chain: []
|
14
|
-
date: 2019-08-
|
14
|
+
date: 2019-08-16 00:00:00.000000000 Z
|
15
15
|
dependencies:
|
16
16
|
- !ruby/object:Gem::Dependency
|
17
17
|
name: mime-types
|