Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse code

Large blobs should be binary

  • Loading branch information...
commit 6e03f954bce62338697a7446d0fbddf0b4ac2dd0 1 parent caa39a2
Joshua Peek josh authored

Showing 2 changed files with 23 additions and 2 deletions. Show diff stats Hide diff stats

  1. +16 2 lib/linguist/blob_helper.rb
  2. +7 0 test/test_blob.rb
18 lib/linguist/blob_helper.rb
@@ -92,8 +92,22 @@ def detect_encoding
92 92 #
93 93 # Return true or false
94 94 def binary?
95   - return false if data.empty?
96   - encoding.nil? || detect_encoding[:type] == :binary
  95 + # Large blobs aren't even loaded into memory
  96 + if data.nil?
  97 + true
  98 +
  99 + # Treat blank files as text
  100 + elsif data == ""
  101 + false
  102 +
  103 + # Charlock doesn't know what to think
  104 + elsif encoding.nil?
  105 + true
  106 +
  107 + # If Charlock says its binary
  108 + else
  109 + detect_encoding[:type] == :binary
  110 + end
97 111 end
98 112
99 113 # Public: Is the blob text?
7 test/test_blob.rb
@@ -84,6 +84,13 @@ def test_encoding
84 84 end
85 85
86 86 def test_binary
  87 + # Large blobs aren't loaded
  88 + large_blob = blob("git.exe")
  89 + large_blob.instance_eval do
  90 + def data; end
  91 + end
  92 + assert large_blob.binary?
  93 +
87 94 assert blob("git.deb").binary?
88 95 assert blob("git.exe").binary?
89 96 assert blob("hello.pbc").binary?

0 comments on commit 6e03f95

Please sign in to comment.
Something went wrong with that request. Please try again.