feat: file edit added

This commit is contained in:
kodi
2026-03-11 14:09:44 +01:00
parent ba6a369f78
commit b93cb01879
18 changed files with 701 additions and 16 deletions
@@ -65,11 +65,25 @@ class FilesystemAdapter:
limit = max_bytes + 1
with path.open("rb") as in_f:
raw = in_f.read(limit)
modified = self.modified_iso(path)
truncated = size > max_bytes or len(raw) > max_bytes
if truncated:
raw = raw[:max_bytes]
return {
"size": size,
"modified": modified,
"truncated": truncated,
"content": raw.decode(encoding, errors="replace"),
}
def write_text_file(self, path: Path, content: str, encoding: str = "utf-8") -> dict:
path.write_text(content, encoding=encoding)
return {
"size": int(path.stat().st_size),
"modified": self.modified_iso(path),
}
@staticmethod
def modified_iso(path: Path) -> str:
stat = path.stat()
return datetime.fromtimestamp(stat.st_mtime, tz=timezone.utc).isoformat().replace("+00:00", "Z")