Skip to content

Commit

Permalink
clean up compressor
Browse files Browse the repository at this point in the history
  • Loading branch information
tim-quix committed Nov 27, 2024
1 parent a09966d commit 610b4e7
Show file tree
Hide file tree
Showing 2 changed files with 3 additions and 17 deletions.
18 changes: 2 additions & 16 deletions quixstreams/sources/community/file/compressions/base.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
import contextlib
from abc import ABC, abstractmethod
from pathlib import Path
from typing import BinaryIO, Literal, Union
from typing import BinaryIO, Literal

__all__ = (
"Decompressor",
Expand All @@ -14,16 +12,4 @@

class Decompressor(ABC):
@abstractmethod
def _decompress(self, filestream: BinaryIO) -> bytes: ...

@contextlib.contextmanager
def _open(self, file: Union[Path, BinaryIO]) -> BinaryIO:
if isinstance(file, Path):
with open(file, "rb") as f:
yield f
else:
yield file

def decompress(self, file: Union[Path, BinaryIO]) -> bytes:
with self._open(file) as filestream:
return self._decompress(filestream)
def decompress(self, filestream: BinaryIO) -> bytes: ...
2 changes: 1 addition & 1 deletion quixstreams/sources/community/file/compressions/gzip.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,5 +10,5 @@ class GZipDecompressor(Decompressor):
def __init__(self):
self._decompressor = decompress

def _decompress(self, filestream: BinaryIO) -> bytes:
def decompress(self, filestream: BinaryIO) -> bytes:
return self._decompressor(filestream.read())

0 comments on commit 610b4e7

Please sign in to comment.