file_type_detector_sfedu 0.2.1 → 0.2.2
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 +4 -4
- data/CHANGELOG.md +5 -0
- data/README.md +10 -2
- data/lib/file_type_detector/version.rb +1 -1
- data/lib/file_type_detector.rb +2 -2
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 58a8d37d3931c29954f7870c6125905261def1d31d71bcd4ebcba1e7499b4a61
|
4
|
+
data.tar.gz: f9201f1e4bfec70f6a63dce6fa652cbac8e215f82078e47f93daff2b4bc661cd
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 1251c06470e171d5fda3eff3a1514253e80305a5cbe8d3e24c190f522e4f445dcd9de2ddbd8f75668737e5c108173bfafaa39b3f4a9daffcaaf2b438acf7e4bf
|
7
|
+
data.tar.gz: 7aed639f2d0f518aa09dbdb711b79695551f5f47e9336df265d8344294d8379ee66ad7b2e3141d342211550803f05dfe4f49f1aa0e8da5982a22e611937a6b1b
|
data/CHANGELOG.md
CHANGED
data/README.md
CHANGED
@@ -28,13 +28,21 @@ puts FileTypeDetector.check("path/to/your/file.pdf") # if it's truly pdf, value
|
|
28
28
|
|
29
29
|
You can also use a specific detector:
|
30
30
|
```ruby
|
31
|
-
puts FileTypeDetector.pdf_check("path/to/your/real_pdf.pdf")
|
32
|
-
puts FileTypeDetector.pdf_check("path/to/your/fake_pdf.pdf")
|
31
|
+
puts FileTypeDetector.pdf_check("path/to/your/real_pdf.pdf") # true
|
32
|
+
puts FileTypeDetector.pdf_check("path/to/your/fake_pdf.pdf") # false
|
33
33
|
|
34
34
|
puts FileTypeDetector.docx_check("path/to/your/real_docx.docx") # true
|
35
35
|
puts FileTypeDetector.docx_check("path/to/your/fake_docx.docx") # false
|
36
36
|
```
|
37
37
|
|
38
|
+
You can also run all the detectors on the file to determine its type using the `identify` method:
|
39
|
+
```ruby
|
40
|
+
puts FileTypeDetector.identify("path/to/your/real_pdf.pdf") # "pdf"
|
41
|
+
puts FileTypeDetector.identify("path/to/your/real_xml.pdf") # "xml"
|
42
|
+
puts FileTypeDetector.identify("path/to/your/real_docx.docx") # docx
|
43
|
+
puts FileTypeDetector.identify("path/to/your/real_jpeg.png") # jpeg
|
44
|
+
puts FileTypeDetector.identify("path/to/your/unknown.png") # nil
|
45
|
+
```
|
38
46
|
## Supported File Types
|
39
47
|
The gem provides support for detecting the following file types:
|
40
48
|
|
data/lib/file_type_detector.rb
CHANGED
@@ -27,7 +27,7 @@ module FileTypeDetector
|
|
27
27
|
def self.identify(file_path)
|
28
28
|
return unless error_handling(file_path)
|
29
29
|
|
30
|
-
FILE_CHECKS.find { |fn| fn.call(file_path)}.name.to_s.split("_")[0]
|
30
|
+
FILE_CHECKS.find { |fn| fn.call(file_path)}.name.to_s.split("_")[0]
|
31
31
|
end
|
32
32
|
|
33
33
|
# =============================================
|
@@ -72,7 +72,7 @@ module FileTypeDetector
|
|
72
72
|
return unless error_handling(file_path)
|
73
73
|
|
74
74
|
first_bytes = File.open(file_path, "rb") { |file| file.read(16) }
|
75
|
-
first_bytes
|
75
|
+
first_bytes&.start_with?("\x89PNG\r\n\x1A\n".b)
|
76
76
|
end
|
77
77
|
|
78
78
|
# Checks if the file has a GIF format.
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: file_type_detector_sfedu
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.2.
|
4
|
+
version: 0.2.2
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Garik Mnacakanyan
|
@@ -11,7 +11,7 @@ authors:
|
|
11
11
|
autorequire:
|
12
12
|
bindir: exe
|
13
13
|
cert_chain: []
|
14
|
-
date: 2024-04-
|
14
|
+
date: 2024-04-08 00:00:00.000000000 Z
|
15
15
|
dependencies: []
|
16
16
|
description: FileTypeDetector is a Ruby gem that provides functionality for determining
|
17
17
|
the type of a file based on its extension or content.
|