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

gitlab.com/gitlab-org/gitlab-foss.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
path: root/lib
diff options
context:
space:
mode:
authorGitLab Bot <gitlab-bot@gitlab.com>2021-03-26 20:34:57 +0300
committerGitLab Bot <gitlab-bot@gitlab.com>2021-03-26 20:34:57 +0300
commitb2ce3643e27db4cc0ad30cc09d651c00ec799887 (patch)
treef0e7882be8145da2f59fec4ac26e070afd147ab9 /lib
parente9143b15cc400b69ef274789225ac2fee5fdcf83 (diff)
Add latest changes from gitlab-org/gitlab@13-10-stable-ee
Diffstat (limited to 'lib')
-rw-r--r--lib/gitlab/utils/mime_type.rb25
1 files changed, 25 insertions, 0 deletions
diff --git a/lib/gitlab/utils/mime_type.rb b/lib/gitlab/utils/mime_type.rb
new file mode 100644
index 00000000000..d82092a2d2c
--- /dev/null
+++ b/lib/gitlab/utils/mime_type.rb
@@ -0,0 +1,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