|
18 | 18 | class VDI: |
19 | 19 | """VirtualBox Virtual Disk Image (VDI) implementation. |
20 | 20 |
|
21 | | - If provided with file-like objects, the caller is responsible for closing them. |
22 | | - When provided with paths, the VDI class will manage the file handles. |
| 21 | + Use :method:`open` to get a stream for reading from the VDI file. The stream will handle reading |
| 22 | + from the parent disk if necessary (and provided). |
| 23 | +
|
| 24 | + If provided with a file-like object, the caller is responsible for closing it. |
| 25 | + When provided with a path, the VDI class will manage the file handle. |
| 26 | +
|
| 27 | + If providing a parent file-like object, the caller is responsible for the lifecycle of that object. |
23 | 28 |
|
24 | 29 | Args: |
25 | 30 | fh: File-like object or path of the VDI file. |
26 | | - parent: Optional file-like object or path for the parent disk (for differencing disks). |
| 31 | + parent: Optional file-like object for the parent disk (for differencing disks). |
27 | 32 | """ |
28 | 33 |
|
29 | | - def __init__(self, fh: BinaryIO | Path, parent: BinaryIO | Path | None = None): |
| 34 | + def __init__(self, fh: BinaryIO | Path, parent: BinaryIO | None = None): |
30 | 35 | if isinstance(fh, Path): |
31 | 36 | self.path = fh |
32 | 37 | self.fh = self.path.open("rb") |
33 | 38 | else: |
34 | 39 | self.path = None |
35 | 40 | self.fh = fh |
36 | 41 |
|
37 | | - if isinstance(parent, Path): |
38 | | - self.parent_path = parent |
39 | | - self.parent = self.parent_path.open("rb") |
40 | | - else: |
41 | | - self.parent_path = None |
42 | | - self.parent = parent |
| 42 | + self.parent = parent |
43 | 43 |
|
44 | 44 | self.fh.seek(0) |
45 | 45 | self.preheader = c_vdi.VDIPREHEADER(self.fh) |
@@ -102,9 +102,6 @@ def close(self) -> None: |
102 | 102 | if self.path is not None: |
103 | 103 | self.fh.close() |
104 | 104 |
|
105 | | - if self.parent_path is not None and self.parent is not None: |
106 | | - self.parent.close() |
107 | | - |
108 | 105 |
|
109 | 106 | class VDIStream(AlignedStream): |
110 | 107 | def __init__(self, vdi: VDI): |
|
0 commit comments