@@ -28,25 +28,27 @@ def send_code(self, code: str) -> Dict:
2828 r = requests .post (url , data = code )
2929 return {'response' : r .text }
3030
31- def get_file (self , filename : str , directory : str = 'gcodes' ) -> str :
31+ def get_file (self , filename : str , directory : str = 'gcodes' , binary : bool = False ) -> str :
3232 """
3333 filename: name of the file you want to download including extension
3434 directory: the folder that the file is in, options are ['gcodes', 'macros', 'sys']
35+ binary: return binary data instead of a string
3536
36- returns the file as a string
37+ returns the file as a string or binary data
3738 """
3839 url = f'{ self .base_url } /machine/file/{ directory } /{ filename } '
3940 r = requests .get (url )
4041 if not r .ok :
4142 raise ValueError
42- return r .text
43+ if binary :
44+ return r .content
45+ else :
46+ return r .text
4347
44- def upload_file (self , file : Union [StringIO , TextIOWrapper ], filename : str , directory : str = 'gcodes' ) -> Dict :
48+ def upload_file (self , file : Union [str , bytes , StringIO , TextIOWrapper , BytesIO ], filename : str , directory : str = 'gcodes' ) -> Dict :
4549 """
4650 file: the path to the file you want to upload from your PC
4751 directory: the folder that the file is in, options are ['gcodes', 'macros', 'sys']
48-
49- returns the file as a string
5052 """
5153 url = f'{ self .base_url } /machine/file/{ directory } /{ filename } '
5254 r = requests .put (url , data = file , headers = {'Content-Type' : 'application/octet-stream' })
0 commit comments