File tree Expand file tree Collapse file tree 1 file changed +29
-0
lines changed Expand file tree Collapse file tree 1 file changed +29
-0
lines changed Original file line number Diff line number Diff line change @@ -96,6 +96,19 @@ def isDir(self, filename):
96
96
from os import path
97
97
return path .isdir (filename )
98
98
99
+ def size (self , id ):
100
+ from os import SEEK_END , SEEK_SET
101
+ if id not in self .files :
102
+ return [None , None ]
103
+ file = self .files [id ]
104
+ try :
105
+ old_position = file .tell ()
106
+ file .seek (0 , SEEK_END )
107
+ size = file .tell ()
108
+ file .seek (old_position , SEEK_SET )
109
+ return [0 , size ]
110
+ except IOError , e :
111
+ return [e .errno , None ]
99
112
100
113
files = Files ()
101
114
@@ -156,6 +169,21 @@ def run(self, data):
156
169
res += chr (pos & 0xFF )
157
170
return res
158
171
172
+ class SIZE_Command :
173
+ def run (self , data ):
174
+ id = ord (data [0 ])
175
+ [err , size ] = files .size (id )
176
+ if size is None :
177
+ size = 0
178
+ if err is None :
179
+ err = 255
180
+ res = chr (err )
181
+ res += chr ((size >> 24 ) & 0xFF )
182
+ res += chr ((size >> 16 ) & 0xFF )
183
+ res += chr ((size >> 8 ) & 0xFF )
184
+ res += chr (size & 0xFF )
185
+ return res
186
+
159
187
160
188
class ISDIRECTORY_Command :
161
189
def run (self , data ):
@@ -175,4 +203,5 @@ def init(command_processor):
175
203
command_processor .register ('i' , ISDIRECTORY_Command ())
176
204
command_processor .register ('s' , SEEK_Command ())
177
205
command_processor .register ('S' , TELL_Command ())
206
+ command_processor .register ('t' , SIZE_Command ())
178
207
You can’t perform that action at this time.
0 commit comments