Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions ext4/block.py
Original file line number Diff line number Diff line change
Expand Up @@ -106,6 +106,9 @@ def peek(self, size: int = 0) -> bytes:
if self.cursor >= len(self):
return b""

if self.cursor + size >= len(self):
size = len(self) - self.cursor

start_index = self.cursor // self.block_size
end_index = (self.cursor + size - 1) // self.block_size
start_offset = self.cursor % self.block_size
Expand Down
12 changes: 11 additions & 1 deletion test.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
import ext4

from typing import cast
from typing import Callable

FAILED = False

Expand All @@ -26,7 +27,7 @@ def test_path_tuple(path: str | bytes, expected: tuple[bytes, ...]):
print(e)


def _assert(source: str):
def _assert(source: str, debug: Callable[[], str] | None = None):
global FAILED
print(f"check {source}: ", end="")
if eval(source):
Expand All @@ -35,6 +36,8 @@ def _assert(source: str):

FAILED = True
print("fail")
if debug is not None:
print(f" {debug()}")


test_path_tuple("/", tuple())
Expand Down Expand Up @@ -91,8 +94,15 @@ def _assert(source: str):
attrs = {k: v for k, v in inode.xattrs}
for j in range(1, 21):
_assert(f'attrs["user.name{j}"] == b"value{i}_{j}"')

data = inode.open().read()
_assert(f'data == b"hello world{i}\\n"')

inode = cast(ext4.File, volume.inode_at("/test1.txt"))
b = inode.open()
data = b"hello world1\n"
for x in range(1, 15):
_assert(f"b.peek({x}) == {data[:x]}", lambda: b.peek(x))

if FAILED:
sys.exit(1)
Loading