Move the quick read function to the document class where it belongs

This commit is contained in:
Veronica Berglyd Olsen
2024-03-26 12:14:07 +01:00
parent 6a7262b817
commit 147d6b95d7
4 changed files with 46 additions and 25 deletions
+2 -15
View File
@@ -289,21 +289,8 @@ class NWStorage:
def getDocumentText(self, tHandle: str) -> str:
"""Return the text of a document in a fast and efficient way."""
if (
isinstance(self._runtimePath, Path)
and (path := self._runtimePath / "content" / f"{tHandle}.nwd").is_file()
):
try:
with open(path, mode="r", encoding="utf-8") as inFile:
line = ""
for _ in range(10):
if not (line := inFile.readline()).startswith(r"%%~"):
break
return line + inFile.read()
except Exception:
logger.error("Cannot read document with handle '%s'", tHandle)
logException()
return ""
if isinstance(self._runtimePath, Path):
return NWDocument.quickReadText(self._runtimePath / "content", tHandle)
return ""
def scanContent(self) -> list[str]: