Skip to content

Commit

Permalink
fix: types
Browse files Browse the repository at this point in the history
Explains the streaming API.
  • Loading branch information
miurahr committed Oct 14, 2024
1 parent 6b8d538 commit 76d7259
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 14 deletions.
19 changes: 8 additions & 11 deletions py7zr/io.py
Original file line number Diff line number Diff line change
Expand Up @@ -49,14 +49,14 @@ class HashIO(Py7zIO):
def __init__(self, filename):
self.filename = filename
self.hash = hashlib.sha256()
self.size = 0
self._size: int = 0

def write(self, s: Union[bytes, bytearray]) -> int:
self.size += len(s)
self._size += len(s)
self.hash.update(s)
return len(s)

def read(self, size: Optional[int] = None) -> bytes:
def read(self, length: Optional[int] = None) -> bytes:
return self.hash.digest()

def seek(self, offset: int, whence: int = 0) -> int:
Expand All @@ -66,7 +66,7 @@ def flush(self) -> None:
pass

def size(self) -> int:
return self.size
return self._size


class Py7zBytesIO(Py7zIO):
Expand Down Expand Up @@ -119,7 +119,7 @@ class BytesIOFactory(WriterFactory):

def __init__(self, limit: int):
self.limit = limit
self.products = {}
self.products: dict[str, Py7zBytesIO] = {}

def create(self, filename: str) -> Py7zIO:
product = Py7zBytesIO(filename, self.limit)
Expand All @@ -141,14 +141,11 @@ def create(self, filename: str) -> Py7zIO:
class MemIO:
"""pathlib.Path-like IO class to write memory"""

def __init__(self, fname: str, factory: Optional[WriterFactory] = None):
def __init__(self, fname: str, factory: WriterFactory):
self._buf: Optional[Py7zIO] = None
self._closed = True
self.fname = fname
if factory is None:
self.factory: WriterFactory = BytesIOFactory()
else:
self.factory = factory
self.factory = factory

@property
def mode(self) -> str:
Expand Down Expand Up @@ -249,7 +246,7 @@ def mkdir(self):
return None

def seek(self, offset: int, whence: int = 0) -> int:
pass
return offset

def size(self):
return 0
Expand Down
3 changes: 1 addition & 2 deletions py7zr/py7zr.py
Original file line number Diff line number Diff line change
Expand Up @@ -535,11 +535,10 @@ def _extract(
self,
path: Optional[Any] = None,
targets: Optional[Collection[str]] = None,
return_dict: bool = False,
callback: Optional[ExtractCallback] = None,
recursive: Optional[bool] = False,
writer_factory: Optional[WriterFactory] = None,
) -> Optional[dict[str, MemIO]]:
) -> None:
if callback is None:
pass
elif isinstance(callback, ExtractCallback):
Expand Down
3 changes: 2 additions & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ test = [
"coverage[toml]>=5.2",
"coveralls>=2.1.1",
"requests",
"pytest-httpserver"
"pytest-httpserver",
]
docs = [
"sphinx>=7.0.0",
Expand All @@ -88,6 +88,7 @@ check = [
"readme-renderer",
"twine",
"black>=24.8.0",
"types-Deprecated"
]
debug = [
"pytest",
Expand Down

0 comments on commit 76d7259

Please sign in to comment.