Browse Source

Fix piping when reads return less data than expected

master
JustAnotherArchivist 2 years ago
parent
commit
c4b62c2fea
1 changed files with 10 additions and 1 deletions
  1. +10
    -1
      zstdwarccat

+ 10
- 1
zstdwarccat View File

@@ -15,7 +15,16 @@ def get_dict(fp):
dictSize = struct.unpack('<I', dictSize)[0]
assert dictSize >= 4, 'dict too small'
assert dictSize < 100 * 1024**2, 'dict too large'
d = fp.read(dictSize)
ds = []
dlen = 0
while dlen < dictSize:
c = fp.read(dictSize - dlen)
if c is None or c == b'': # EOF
break
ds.append(c)
dlen += len(c)
d = b''.join(ds)
assert len(d) == dictSize, f'could not read dict fully: expected {dictSize}, got {len(d)}'
assert d.startswith(b'\x28\xB5\x2F\xFD') or d.startswith(b'\x37\xA4\x30\xEC'), 'not a valid dict'
if d.startswith(b'\x28\xB5\x2F\xFD'): # Compressed dict
# Decompress with unzstd


Loading…
Cancel
Save