lib/metadata/mime_info.rb
# fallback to a simple way of determining whether it's
# a text file or a binary
fallback to a simple way of determining whether it's
a text file or a binary
fallback to a simple way of determining whether it ' s a text file or a binary
def text_or_binary(filename)
    type = "text/plain"
    stat = File.stat(filename)
    File.open(filename) {|f|
      data = f.read((stat.size < 32) ? stat.size : 32)
      data.each_byte do |b|
        if b < 32 && b != 9 && b != 10 && b != 13
          type = "application/octet-stream"
          break
        end
      end
    }
    type
  rescue IOError, SystemCallError
    nil
  end
def text_or_binary ( filename ) type = "text/plain" stat = File . stat ( filename ) File . open ( filename ) { | f | data = f . read ( ( stat . size < 32 ) ? stat . size : 32 ) data . each_byte do | b | if b < 32 && b != 9 && b != 10 && b != 13 type = "application/octet-stream" break end end } type rescue IOError , SystemCallError nil end
fallback to a simple way of determining whether it's
a text file or a binary
fallback to a simple way of determining whether it ' s a text file or a binary
# check the first 32 bytes for ASCII control characters
filename
<not_specific>