File tree 1 file changed +33
-0
lines changed
1 file changed +33
-0
lines changed Original file line number Diff line number Diff line change
1
+ from moban import utils , file_system
2
+
3
+ import fs
4
+ import fs .path
5
+
6
+
7
+ class BufferedWriter (object ):
8
+ def __init__ (self ):
9
+ self .fs_list = {}
10
+
11
+ def write_file_out (self , filename , content ):
12
+ if "zip://" in filename :
13
+ self .write_file_out_to_zip (filename , content )
14
+ else :
15
+ utils .write_file_out (filename , content )
16
+
17
+ def write_file_out_to_zip (self , filename , content ):
18
+ zip_file , file_name = filename .split (".zip/" )
19
+ zip_file = zip_file + ".zip"
20
+ if zip_file not in self .fs_list :
21
+ self .fs_list [zip_file ] = fs .open_fs (
22
+ file_system .to_unicode (zip_file ), create = True
23
+ )
24
+ base_dirs = fs .path .dirname (file_name )
25
+ if not self .fs_list [zip_file ].exists (base_dirs ):
26
+ self .fs_list [zip_file ].makedirs (base_dirs )
27
+ self .fs_list [zip_file ].writebytes (
28
+ file_system .to_unicode (file_name ), content
29
+ )
30
+
31
+ def close (self ):
32
+ for fsx in self .fs_list .values ():
33
+ fsx .close ()
You can’t perform that action at this time.
0 commit comments