소스 검색

Fix piping when reads return less data than expected

master
JustAnotherArchivist 2 년 전
부모
커밋
c4b62c2fea
1개의 변경된 파일10개의 추가작업 그리고 1개의 파일을 삭제
  1. +10
    -1
      zstdwarccat

+ 10
- 1
zstdwarccat 파일 보기

@@ -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


불러오는 중...
취소
저장