@@ -80,26 +80,32 @@ def unlink(self, fpath: str) -> None:
80
80
except base .NotConnectedError as error :
81
81
raise ConnectionError (f"unlink: { error } " )
82
82
83
- def write_text (self , fpath : str , teststr : str ) -> None :
83
+ def write (self , fpath : str , writeobj : typing . IO ) -> None :
84
84
try :
85
- with io .BytesIO (teststr .encode ()) as writeobj :
86
- self .ctx .storeFile (self .share , fpath , writeobj )
85
+ self .ctx .storeFile (self .share , fpath , writeobj )
87
86
except smb_structs .OperationFailure as error :
88
87
raise IOError (f"failed in write_text: { error } " )
89
88
except base .SMBTimeout as error :
90
89
raise TimeoutError (f"write_text: { error } " )
91
90
except base .NotConnectedError as error :
92
91
raise ConnectionError (f"write: { error } " )
93
92
94
- def read_text (self , fpath : str ) -> str :
93
+ def read (self , fpath : str , readobj : typing . IO ) -> None :
95
94
try :
96
- with io .BytesIO () as readobj :
97
- self .ctx .retrieveFile (self .share , fpath , readobj )
98
- ret = readobj .getvalue ().decode ("utf8" )
95
+ self .ctx .retrieveFile (self .share , fpath , readobj )
99
96
except smb_structs .OperationFailure as error :
100
97
raise IOError (f"failed in read_text: { error } " )
101
98
except base .SMBTimeout as error :
102
99
raise TimeoutError (f"read_text: { error } " )
103
100
except base .NotConnectedError as error :
104
101
raise ConnectionError (f"read: { error } " )
102
+
103
+ def write_text (self , fpath : str , teststr : str ) -> None :
104
+ with io .BytesIO (teststr .encode ()) as writeobj :
105
+ self .write (fpath , writeobj )
106
+
107
+ def read_text (self , fpath : str ) -> str :
108
+ with io .BytesIO () as readobj :
109
+ self .read (fpath , readobj )
110
+ ret = readobj .getvalue ().decode ("utf8" )
105
111
return ret
0 commit comments