Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Large blobs should be binary

  • Loading branch information...
commit 6e03f954bce62338697a7446d0fbddf0b4ac2dd0 1 parent caa39a2
@josh josh authored
Showing with 23 additions and 2 deletions.
  1. +16 −2 lib/linguist/blob_helper.rb
  2. +7 −0 test/test_blob.rb
View
18 lib/linguist/blob_helper.rb
@@ -92,8 +92,22 @@ def detect_encoding
#
# Return true or false
def binary?
- return false if data.empty?
- encoding.nil? || detect_encoding[:type] == :binary
+ # Large blobs aren't even loaded into memory
+ 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
# Public: Is the blob text?
View
7 test/test_blob.rb
@@ -84,6 +84,13 @@ def test_encoding
end
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.exe").binary?
assert blob("hello.pbc").binary?
Please sign in to comment.
Something went wrong with that request. Please try again.