From d8e2f8a92ab43009f296642b38c9c0794b8b5c82 Mon Sep 17 00:00:00 2001 From: "R. Richard" Date: Tue, 25 Jun 2019 11:31:27 +0200 Subject: [PATCH] Make file operations unbuffered --- lib/tfw/components/file_manager/file_manager.py | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/lib/tfw/components/file_manager/file_manager.py b/lib/tfw/components/file_manager/file_manager.py index 967e06f..0e4fc6a 100644 --- a/lib/tfw/components/file_manager/file_manager.py +++ b/lib/tfw/components/file_manager/file_manager.py @@ -65,13 +65,13 @@ class FileManager: # pylint: disable=too-many-instance-attributes @property def file_contents(self): - with open(self._filepath(self.filename), 'r', errors='surrogateescape') as ifile: - return ifile.read() + with open(self._filepath(self.filename), 'rb', buffering=0) as ifile: + return ifile.read().decode(errors='surrogateescape') @file_contents.setter def file_contents(self, value): - with open(self._filepath(self.filename), 'w', errors='surrogateescape') as ofile: - ofile.write(value) + with open(self._filepath(self.filename), 'wb', buffering=0) as ofile: + ofile.write(value.encode()) def _is_in_allowed_dir(self, path): return any(