Welcome to mirror list, hosted at ThFree Co, Russian Federation.

mime_type.rb « utils « gitlab « lib - gitlab.com/gitlab-org/gitlab-foss.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
blob: d82092a2d2c12d21fcf7697ce5e12a509d9b9328 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
# frozen_string_literal: true
require 'magic'

# This wraps calls to a gem which support mime type detection.
# We use the `ruby-magic` gem instead of `mimemagic` due to licensing issues
module Gitlab
  module Utils
    class MimeType
      class << self
        def from_io(io)
          return unless io.is_a?(IO) || io.is_a?(StringIO)

          mime_type = File.magic(io, Magic::MIME_TYPE)
          mime_type == 'inode/x-empty' ? nil : mime_type
        end

        def from_string(string)
          return unless string.is_a?(String)

          string.type
        end
      end
    end
  end
end