From 49dffd9ef79627f98bca5e1915488be6838b6cda Mon Sep 17 00:00:00 2001 From: hut Date: Wed, 31 Mar 2010 04:48:56 +0200 Subject: fsobject.file: read more than 4 bytes for is_binary --- ranger/fsobject/file.py | 15 ++++++--------- 1 file changed, 6 insertions(+), 9 deletions(-) diff --git a/ranger/fsobject/file.py b/ranger/fsobject/file.py index 15bfc18b..aa44016e 100644 --- a/ranger/fsobject/file.py +++ b/ranger/fsobject/file.py @@ -14,30 +14,27 @@ # along with this program. If not, see . control_characters = set(chr(n) for n in set(range(0, 9)) | set(range(14,32))) +N_FIRST_BYTES = 20 from .fsobject import FileSystemObject as SuperClass class File(SuperClass): is_file = True @property - def first4bytes(self): + def firstbytes(self): try: - return self._first4bytes + return self._firstbytes except: try: f = open(self.path, 'r') - self._first4bytes = f.read(4) + self._firstbytes = f.read(N_FIRST_BYTES) f.close() - return self._first4bytes + return self._firstbytes except: pass def is_binary(self): - if not self.first4bytes: - return - if self.first4bytes == "\x7F\x45\x4C\x46": - return True - if control_characters & set(self.first4bytes): + if self.firstbytes and control_characters & set(self.firstbytes): return True return False -- cgit 1.4.1-2-gfad0