media file: factor out file type detection code.

Factor out the file type detection code from MediaFile into a FileTypeDetector class so we can use
it to detect archive files (.zip, .rar, .7z) too.
This commit is contained in:
evazion
2022-11-14 15:46:08 -06:00
parent 0c1e9a1618
commit 5f92f452fe
3 changed files with 78 additions and 49 deletions

View File

@@ -155,7 +155,12 @@ module Danbooru
false
end
# @return [String] The archive format ("RAR", "ZIP", etc).
# @return [Symbol] The archive format as detected by us (:zip, :rar, :7z, etc).
def file_ext
@file_ext ||= FileTypeDetector.new(file).file_ext
end
# @return [String] The archive format as returned by libarchive ("RAR", "ZIP", etc).
def format
@format ||= entries.lazy.map(&:format).first
end