summary refs log tree commit diff stats
diff options
context:
space:
mode:
authorhut <hut@lavabit.com>2010-03-31 04:48:56 +0200
committerhut <hut@lavabit.com>2010-03-31 04:48:56 +0200
commit49dffd9ef79627f98bca5e1915488be6838b6cda (patch)
tree0863c43ffff84e773918508d410630d088b05a00
parenta43d9f57312688c54947b4338dbbd0dead7e142d (diff)
downloadranger-49dffd9ef79627f98bca5e1915488be6838b6cda.tar.gz
fsobject.file: read more than 4 bytes for is_binary
-rw-r--r--ranger/fsobject/file.py15
1 files 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 <http://www.gnu.org/licenses/>.
 
 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