Sha256: 0f278a4a1da174444facd521ea3b1dcef089e1ec2122610f651b640df21b66e2

Contents?: true

Size: 691 Bytes

Versions: 155

Compression:

Stored size: 691 Bytes

Contents

# frozen_string_literal: true

require 'eac_ruby_utils/core_ext'
require 'content-type'
require 'filemagic'

module EacFs
  class FileInfo
    UNKNOWN_CONTENT_TYPE_STRING = 'application/octet-stream'
    UNKNOWN_CONTENT_TYPE = ::ContentType.parse(UNKNOWN_CONTENT_TYPE_STRING)

    enable_simple_cache
    attr_reader :magic_string

    def initialize(path)
      @magic_string = ::FileMagic.new(FileMagic::MAGIC_MIME).file(path.to_pathname.to_path)
    end

    delegate :charset, :mime_type, :subtype, :type, to: :content_type

    private

    def content_type_uncached
      ::ContentType.parse(magic_string)
    rescue ::Parslet::ParseFailed
      UNKNOWN_CONTENT_TYPE
    end
  end
end

Version data entries

155 entries across 155 versions & 4 rubygems

Version Path
eac_tools-0.28.0 sub/eac_fs/lib/eac_fs/file_info.rb
eac_tools-0.27.2 sub/eac_fs/lib/eac_fs/file_info.rb
eac_tools-0.27.1 sub/eac_fs/lib/eac_fs/file_info.rb
eac_tools-0.27.0 sub/eac_fs/lib/eac_fs/file_info.rb
eac_tools-0.26.0 sub/eac_fs/lib/eac_fs/file_info.rb
eac_tools-0.25.1 sub/eac_fs/lib/eac_fs/file_info.rb
eac_tools-0.25.0 sub/eac_fs/lib/eac_fs/file_info.rb
eac_tools-0.24.1 sub/eac_fs/lib/eac_fs/file_info.rb
eac_tools-0.24.0 sub/eac_fs/lib/eac_fs/file_info.rb
eac_tools-0.23.0 sub/eac_fs/lib/eac_fs/file_info.rb
eac_tools-0.22.0 sub/eac_fs/lib/eac_fs/file_info.rb
eac_tools-0.21.0 sub/eac_fs/lib/eac_fs/file_info.rb
eac_tools-0.20.0 sub/eac_fs/lib/eac_fs/file_info.rb
eac_tools-0.19.0 sub/eac_fs/lib/eac_fs/file_info.rb
eac_tools-0.18.0 sub/eac_fs/lib/eac_fs/file_info.rb
eac_tools-0.17.0 sub/eac_fs/lib/eac_fs/file_info.rb
eac_tools-0.16.1 sub/eac_fs/lib/eac_fs/file_info.rb
eac_tools-0.16.0 sub/eac_fs/lib/eac_fs/file_info.rb
eac_tools-0.15.0 sub/eac_fs/lib/eac_fs/file_info.rb
eac_tools-0.14.0 sub/eac_fs/lib/eac_fs/file_info.rb