summary refs log tree commit diff stats
path: root/ranger
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 /ranger
parenta43d9f57312688c54947b4338dbbd0dead7e142d (diff)
downloadranger-49dffd9ef79627f98bca5e1915488be6838b6cda.tar.gz
fsobject.file: read more than 4 bytes for is_binary
Diffstat (limited to 'ranger')
-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
 
00 updated UML project' href='/akspecs/ranger/commit/uml/134530.diagram?h=v1.8.0&id=61de0a4defd3fe275f6f51fe81f362b0adbdf382'>61de0a4d ^
cfbb8c84 ^
61de0a4d ^
cfbb8c84 ^
61de0a4d ^
cfbb8c84 ^
61de0a4d ^
cfbb8c84 ^
61de0a4d ^
cfbb8c84 ^
61de0a4d ^
cfbb8c84 ^
61de0a4d ^
cfbb8c84 ^
61de0a4d ^
cfbb8c84 ^
61de0a4d ^
cfbb8c84 ^
61de0a4d ^
cfbb8c84 ^
61de0a4d ^
cfbb8c84 ^
61de0a4d ^


cfbb8c84 ^
61de0a4d ^
cfbb8c84 ^
61de0a4d ^
cfbb8c84 ^
61de0a4d ^
cfbb8c84 ^
61de0a4d ^
cfbb8c84 ^
61de0a4d ^
cfbb8c84 ^
61de0a4d ^
9f186528 ^
61de0a4d ^
9f186528 ^
61de0a4d ^
9f186528 ^
8db3c4b1 ^
9f186528 ^
6f43de0a ^
9f186528 ^
61de0a4d ^
9f186528 ^
61de0a4d ^
9f186528 ^
61de0a4d ^
9f186528 ^
61de0a4d ^
9f186528 ^
61de0a4d ^


cfbb8c84 ^
61de0a4d ^

69a0e827 ^



61de0a4d ^


cfbb8c84 ^


61de0a4d ^

cfbb8c84 ^


61de0a4d ^



cfbb8c84 ^


61de0a4d ^



cfbb8c84 ^


61de0a4d ^

cfbb8c84 ^


61de0a4d ^


cfbb8c84 ^


61de0a4d ^


cfbb8c84 ^


61de0a4d ^


cfbb8c84 ^


61de0a4d ^

cfbb8c84 ^


61de0a4d ^

cfbb8c84 ^


61de0a4d ^



cfbb8c84 ^


61de0a4d ^



9f186528 ^


61de0a4d ^

9f186528 ^


61de0a4d ^

9f186528 ^


61de0a4d ^


9f186528 ^


61de0a4d ^

9f186528 ^


61de0a4d ^

9f186528 ^


61de0a4d ^
6f43de0a ^
9f186528 ^


69a0e827 ^









cfbb8c84 ^
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190