-
Notifications
You must be signed in to change notification settings - Fork 11
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
ZeroDivisionError in the end of zip file #13
Comments
Thanks for the report! I have reproduced the issue, and am investigating. |
I'm not entirely sure that this isn't an issue with httpx... it surprises me it yields any zero-length chunks, even at the end. I've started a discussion at encode/httpx#1733 In the meantime, you can filter out zero-length chunks with an intermediate generator: import httpx
from stream_unzip import stream_unzip
def without_zero_length(chunks):
for chunk in chunks:
if chunk:
yield chunk
def zipped_chunks():
with httpx.stream('GET', 'https://www.gyan.dev/ffmpeg/builds/packages/ffmpeg-4.4-essentials_build.zip') as r:
yield from without_zero_length(r.iter_bytes())
for file_name, file_size, unzipped_chunks in stream_unzip(zipped_chunks()):
for chunk in unzipped_chunks:
print(file_name, file_size) |
Ah, or in this case httpx
Suspect you can only replace |
Ah found a more robust workaround: specifying import httpx
from stream_unzip import stream_unzip
def zipped_chunks():
with httpx.stream('GET', 'https://www.gyan.dev/ffmpeg/builds/packages/ffmpeg-4.4-essentials_build.zip') as r:
yield from r.iter_bytes(chunk_size=65536)
for file_name, file_size, unzipped_chunks in stream_unzip(zipped_chunks()):
for chunk in unzipped_chunks:
print(file_name, file_size) |
I've opted to not change the code, and instead change the README to have an example that works, and explicitly state that zero length chunks are not supported. It's a tricky call to make, but all things being equal, I'm happier with the error since it indicates something is unexpected earlier in the processing. [If users do want to not fail with zero-length chunks, then they can filter them out as in the example above] |
Thanks for the lib.
Got
ZeroDivisionError: integer division or modulo by zero
during processing zip file's last chunk from example code snippet:Code snippet:
Python 3.9.5 (Windows 10)
stream-unzip 0.0.23
The text was updated successfully, but these errors were encountered: