Skip to content

Commit

Permalink
Improve file opening
Browse files Browse the repository at this point in the history
  • Loading branch information
Schamper committed Mar 18, 2024
1 parent 863e0e6 commit dfd732f
Showing 1 changed file with 6 additions and 4 deletions.
10 changes: 6 additions & 4 deletions dissect/archive/wim.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
from functools import cached_property, lru_cache
from typing import BinaryIO, Callable, Iterator, Optional

from dissect.util.stream import AlignedStream, RelativeStream
from dissect.util.stream import AlignedStream, BufferedStream, RelativeStream
from dissect.util.ts import wintimestamp

from dissect.archive.c_wim import (
Expand Down Expand Up @@ -361,9 +361,11 @@ def open(self, name: str = "") -> BinaryIO:
if stream_hash is None:
raise FileNotFoundError(f"Stream not found in directory entry {self}: {name!r}")

for resource in self.image.wim.resources():
if resource.hash == stream_hash:
return resource.open()
if stream_hash.strip(b"\x00") == b"":
return BufferedStream(io.BytesIO(b""), size=0)

if resource := self.image.wim._resource_table.get(stream_hash):
return resource.open()
else:
raise FileNotFoundError(f"Unable to find resource for directory entry {self}")

Expand Down

0 comments on commit dfd732f

Please sign in to comment.