diff -r 670f234271d8 -r 75b656c80a40 src/eric7/RemoteServerInterface/EricServerFileSystemInterface.py --- a/src/eric7/RemoteServerInterface/EricServerFileSystemInterface.py Sun Feb 18 17:46:53 2024 +0100 +++ b/src/eric7/RemoteServerInterface/EricServerFileSystemInterface.py Mon Feb 19 15:33:33 2024 +0100 @@ -15,6 +15,7 @@ from PyQt6.QtCore import QEventLoop, QObject, pyqtSlot +from eric7 import Utilities from eric7.RemoteServer.EricRequestCategory import EricRequestCategory from eric7.SystemUtilities import FileSystemUtilities @@ -958,3 +959,61 @@ loop.exec() if not ok: raise OSError(error) + + def readEncodedFile(self, filename, create=False): + """ + Function to read a file and decode its contents into proper text. + + @param filename name of the file to read + @type str + @param create flag indicating to create an empty file, if it does not exist + (defaults to False) + @type bool (optional) + @return tuple of decoded text and encoding + @rtype tuple of (str, str) + """ + data = self.readFile(filename, create=create) + return Utilities.decode(data) + + def readEncodedFileWithEncoding(self, filename, encoding, create=False): + """ + Function to read a file and decode its contents into proper text. + + @param filename name of the file to read + @type str + @param encoding encoding to be used to read the file + @type str + @param create flag indicating to create an empty file, if it does not exist + (defaults to False) + @type bool (optional) + @return tuple of decoded text and encoding + @rtype tuple of (str, str) + """ + data = self.readFile(filename, create=create) + return Utilities.decodeWithEncoding(data, encoding) + + def writeEncodedFile(self, filename, text, origEncoding, forcedEncoding="", withBackup=False): + """ + Function to write a file with properly encoded text. + + @param filename name of the file to read + @type str + @param text text to be written + @type str + @param origEncoding type of the original encoding + @type str + @param forcedEncoding encoding to be used for writing, if no coding + line is present (defaults to "") + @type str (optional) + @param withBackup flag indicating to create a backup file first + (defaults to False) + @type bool (optional) + @return encoding used for writing the file + @rtype str + """ + data, encoding = Utilities.encode( + text, origEncoding, forcedEncoding=forcedEncoding + ) + self.writeFile(filename, data, withBackup=withBackup) + + return encoding