mirror of
https://github.com/KevinMidboe/linguist.git
synced 2025-12-08 20:38:47 +00:00
Large blobs should be binary
This commit is contained in:
@@ -92,8 +92,22 @@ module Linguist
|
|||||||
#
|
#
|
||||||
# Return true or false
|
# Return true or false
|
||||||
def binary?
|
def binary?
|
||||||
return false if data.empty?
|
# Large blobs aren't even loaded into memory
|
||||||
encoding.nil? || detect_encoding[:type] == :binary
|
if data.nil?
|
||||||
|
true
|
||||||
|
|
||||||
|
# Treat blank files as text
|
||||||
|
elsif data == ""
|
||||||
|
false
|
||||||
|
|
||||||
|
# Charlock doesn't know what to think
|
||||||
|
elsif encoding.nil?
|
||||||
|
true
|
||||||
|
|
||||||
|
# If Charlock says its binary
|
||||||
|
else
|
||||||
|
detect_encoding[:type] == :binary
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
# Public: Is the blob text?
|
# Public: Is the blob text?
|
||||||
|
|||||||
@@ -84,6 +84,13 @@ class TestBlob < Test::Unit::TestCase
|
|||||||
end
|
end
|
||||||
|
|
||||||
def test_binary
|
def test_binary
|
||||||
|
# Large blobs aren't loaded
|
||||||
|
large_blob = blob("git.exe")
|
||||||
|
large_blob.instance_eval do
|
||||||
|
def data; end
|
||||||
|
end
|
||||||
|
assert large_blob.binary?
|
||||||
|
|
||||||
assert blob("git.deb").binary?
|
assert blob("git.deb").binary?
|
||||||
assert blob("git.exe").binary?
|
assert blob("git.exe").binary?
|
||||||
assert blob("hello.pbc").binary?
|
assert blob("hello.pbc").binary?
|
||||||
|
|||||||
Reference in New Issue
Block a user