feat: file viewer added
This commit is contained in:
Binary file not shown.
@@ -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"),
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user