feat: file viewer added

This commit is contained in:
kodi
2026-03-11 13:53:59 +01:00
parent 31a42d34c7
commit ba6a369f78
16 changed files with 550 additions and 2 deletions
@@ -59,3 +59,17 @@ class FilesystemAdapter:
if on_progress:
on_progress(out_f.tell())
shutil.copystat(src, dst, follow_symlinks=False)
def read_text_preview(self, path: Path, max_bytes: int, encoding: str = "utf-8") -> dict:
size = int(path.stat().st_size)
limit = max_bytes + 1
with path.open("rb") as in_f:
raw = in_f.read(limit)
truncated = size > max_bytes or len(raw) > max_bytes
if truncated:
raw = raw[:max_bytes]
return {
"size": size,
"truncated": truncated,
"content": raw.decode(encoding, errors="replace"),
}