mirror of
https://github.com/KevinMidboe/linguist.git
synced 2025-10-29 17:50:22 +00:00
Use Charlock all the time for binary detection
This commit is contained in:
@@ -53,8 +53,7 @@ module Linguist
|
||||
#
|
||||
# Returns a content type String.
|
||||
def content_type
|
||||
@content_type ||= binary? ?
|
||||
mime_type :
|
||||
@content_type ||= binary? ? mime_type :
|
||||
(encoding ? "text/plain; charset=#{encoding.downcase}" : "text/plain")
|
||||
end
|
||||
|
||||
@@ -93,11 +92,8 @@ module Linguist
|
||||
#
|
||||
# Return true or false
|
||||
def binary?
|
||||
if mime_type = Mime.lookup_mime_type_for(pathname.extname)
|
||||
mime_type.binary?
|
||||
else
|
||||
encoding.nil? || detect_encoding[:type] == :binary
|
||||
end
|
||||
return false if data.empty?
|
||||
encoding.nil? || detect_encoding[:type] == :binary
|
||||
end
|
||||
|
||||
# Public: Is the blob text?
|
||||
|
||||
@@ -58,26 +58,6 @@ module Linguist
|
||||
mime_type ? mime_type.simplified : 'text/plain'
|
||||
end
|
||||
|
||||
# Internal: Determine if extension or mime type is binary.
|
||||
#
|
||||
# ext_or_mime_type - A file extension ".exe" or
|
||||
# mime type "application/octet-stream".
|
||||
#
|
||||
# Returns true or false
|
||||
def self.binary?(ext_or_mime_type)
|
||||
mime_type = lookup_mime_type_for(ext_or_mime_type)
|
||||
mime_type ? mime_type.binary? : false
|
||||
end
|
||||
|
||||
# Internal: Determine if extension or mime type is plain text.
|
||||
#
|
||||
# ext_or_mime_type - A file extension ".txt" or mime type "text/plain".
|
||||
#
|
||||
# Returns true or false
|
||||
def self.text?(ext_or_mime_type)
|
||||
!binary?(ext_or_mime_type)
|
||||
end
|
||||
|
||||
# Internal: Lookup mime type for extension or mime type
|
||||
#
|
||||
# ext_or_mime_type - A file extension ".txt" or mime type "text/plain".
|
||||
|
||||
@@ -77,27 +77,6 @@ module Linguist
|
||||
@mime_type ||= Mime.mime_for(extname)
|
||||
end
|
||||
|
||||
# Public: Get the Content-Type header
|
||||
#
|
||||
# This value is used when serving raw blobs.
|
||||
#
|
||||
# Examples
|
||||
#
|
||||
# Pathname.new('file.txt').content_type
|
||||
# # => 'text/plain; charset=utf-8'
|
||||
#
|
||||
# Returns a content type String.
|
||||
def content_type
|
||||
@content_type ||= binary? ? mime_type : 'text/plain; charset=utf8'
|
||||
end
|
||||
|
||||
# Public: Is the path binary?
|
||||
#
|
||||
# Return true or false
|
||||
def binary?
|
||||
@binary ||= Mime.binary?(extname)
|
||||
end
|
||||
|
||||
# Public: Return self as String
|
||||
#
|
||||
# Returns a String
|
||||
|
||||
Reference in New Issue
Block a user