-
Notifications
You must be signed in to change notification settings - Fork 91
Add support for VDI changes #1531
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -17,11 +17,9 @@ class VdiContainer(Container): | |
| __type__ = "vdi" | ||
|
|
||
| def __init__(self, fh: BinaryIO | Path, *args, **kwargs): | ||
| f = fh | ||
| if not hasattr(fh, "read"): | ||
| f = fh.open("rb") | ||
| self.vdi = vdi.VDI(f) | ||
| self.vdi = vdi.VDI(fh) | ||
|
|
||
| self._stream = self.vdi.open() | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The API suggests a symmetry between vdi.open() and vdi.close() that doesn't actually exist. In reality, the code operates on different levels of abstraction. The VDI acts as a manager that you shut down using vdi.close() (Level 1). One option would be to rename vdi.open() to vdi.get_stream() or vdi.create_stream().
Member
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Most of these things can be ironed out once we can seriously get into making #100 happen. Currently changes around this are mostly around having the ability to create separate streams from container formats within their implementation. Any changes in |
||
| super().__init__(fh, self.vdi.size, *args, **kwargs) | ||
|
|
||
| @staticmethod | ||
|
|
@@ -33,13 +31,14 @@ def detect_path(path: Path, original: list | BinaryIO) -> bool: | |
| return path.suffix.lower() == ".vdi" | ||
|
|
||
| def read(self, length: int) -> bytes: | ||
| return self.vdi.read(length) | ||
| return self._stream.read(length) | ||
|
|
||
| def seek(self, offset: int, whence: int = io.SEEK_SET) -> int: | ||
| return self.vdi.seek(offset, whence) | ||
| return self._stream.seek(offset, whence) | ||
|
|
||
| def tell(self) -> int: | ||
| return self.vdi.tell() | ||
| return self._stream.tell() | ||
|
|
||
| def close(self) -> None: | ||
| pass | ||
| self._stream.close() | ||
| self.vdi.close() | ||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
As the lifecycle of the stream coincide in vdi in this usecase, and perhaps in most of the usecases, an alternative design would be to let VDI implement stream methods in terms of an internal
VDISttream, and provide a factory method to get a freshVDIStream,