|
|
@ -29,7 +29,8 @@ class StreamingDecompressor: |
|
|
|
self.sha256 = hashlib.sha256() |
|
|
|
self.sha256 = hashlib.sha256() |
|
|
|
|
|
|
|
|
|
|
|
def read(self, length: int) -> bytes: |
|
|
|
def read(self, length: int) -> bytes: |
|
|
|
while len(self.buf) < length: |
|
|
|
while len(self.buf) < length and not self.eof: |
|
|
|
|
|
|
|
if self.decompressor.needs_input: |
|
|
|
self.req.raise_for_status() |
|
|
|
self.req.raise_for_status() |
|
|
|
|
|
|
|
|
|
|
|
try: |
|
|
|
try: |
|
|
@ -37,8 +38,14 @@ class StreamingDecompressor: |
|
|
|
except StopIteration: |
|
|
|
except StopIteration: |
|
|
|
self.eof = True |
|
|
|
self.eof = True |
|
|
|
break |
|
|
|
break |
|
|
|
out = self.decompressor.decompress(compressed) |
|
|
|
else: |
|
|
|
self.buf += out |
|
|
|
compressed = b'' |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
self.buf += self.decompressor.decompress(compressed, max_length=length) |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if self.decompressor.eof: |
|
|
|
|
|
|
|
self.eof = True |
|
|
|
|
|
|
|
break |
|
|
|
|
|
|
|
|
|
|
|
result = self.buf[:length] |
|
|
|
result = self.buf[:length] |
|
|
|
self.buf = self.buf[length:] |
|
|
|
self.buf = self.buf[length:] |
|
|
@ -83,8 +90,8 @@ def unsparsify(f: StreamingDecompressor) -> Generator[bytes, None, None]: |
|
|
|
|
|
|
|
|
|
|
|
# noop wrapper with same API as unsparsify() for non sparse images |
|
|
|
# noop wrapper with same API as unsparsify() for non sparse images |
|
|
|
def noop(f: StreamingDecompressor) -> Generator[bytes, None, None]: |
|
|
|
def noop(f: StreamingDecompressor) -> Generator[bytes, None, None]: |
|
|
|
while not f.eof: |
|
|
|
while len(chunk := f.read(1024 * 1024)) > 0: |
|
|
|
yield f.read(1024 * 1024) |
|
|
|
yield chunk |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
def get_target_slot_number() -> int: |
|
|
|
def get_target_slot_number() -> int: |
|
|
|