You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
fromzstandardimportZstdDecompressorfromzstandardimportZstdCompressorfromcStringIOimportStringIOimportosdefzstd_readlines(handle):
""" Read data from a Zstandard-compressed stream and split by newlines. Returns an iterator over the stream. :param file handle: the file to read from :return: a generator that yields text lines :rtype : Iterator[unicode] """decompressor=ZstdDecompressor()
withdecompressor.stream_reader(handle) asreader:
whileTrue:
read=reader.read(8192)
ifnotread:
breakdefcompress(data):
handle=StringIO()
compressor=ZstdCompressor()
withcompressor.stream_writer(handle) aswriter:
writer.write(data)
handle.seek(0)
returnhandledata=bytearray(os.urandom(1000000))
handle=compress(data)
zstd_readlines(handle)
print"Success"
(venv) root@a74460b9653b:~# pypy read.py
Traceback (most recent call last):
File "read4.py", line 33, in <module>
zstd_readlines(handle)
File "read4.py", line 17, in zstd_readlines
read = reader.read(8192)
File "/opt/awn/venv/site-packages/zstd_cffi.py", line 1521, in read
result = decompress()
File "/opt/awn/venv/site-packages/zstd_cffi.py", line 1491, in decompress
_zstd_error(zresult))
ZstdError: (u'zstd decompress error: %s', u'Corrupted block detected')
(venv) root@a74460b9653b:~# export PYTHON_ZSTANDARD_IMPORT_POLICY='cext'
(venv) root@a74460b9653b:~# pypy read.py
Success
(venv) root@a74460b9653b:~#
We worked around with by switching to read_to_iter, but block reading should work as well.
The text was updated successfully, but these errors were encountered:
Here is simple example of the broken behaviour
We worked around with by switching to read_to_iter, but block reading should work as well.
The text was updated successfully, but these errors were encountered: