ZeroDivisionError in the end of zip file
See original GitHub issueThanks for the lib.
Got ZeroDivisionError: integer division or modulo by zero
during processing zip file’s last chunk from example code snippet:
Traceback (most recent call last):
File "***\tmp.py", line 9, in <module>
for file_name, file_size, unzipped_chunks in stream_unzip(zipped_chunks()):
File "***\venv_win32_39py\lib\site-packages\stream_unzip.py", line 180, in stream_unzip
for _ in yield_all():
File "***\venv_win32_39py\lib\site-packages\stream_unzip.py", line 35, in _yield_all
offset = (offset + to_yield) % len(chunk)
ZeroDivisionError: integer division or modulo by zero
Code snippet:
import httpx
from stream_unzip import stream_unzip
def zipped_chunks():
# Any iterable that yields a zip file
with httpx.stream('GET', 'https://www.gyan.dev/ffmpeg/builds/packages/ffmpeg-4.4-essentials_build.zip') as r:
yield from r.iter_bytes()
for file_name, file_size, unzipped_chunks in stream_unzip(zipped_chunks()):
for chunk in unzipped_chunks:
# print(chunk)
print(file_name, file_size)
Python 3.9.5 (Windows 10) stream-unzip 0.0.23
Issue Analytics
- State:
- Created 2 years ago
- Comments:5 (5 by maintainers)
Top Results From Across the Web
division by zero occurs while requesting NHL data and writing ...
1 Answer 1 ... The reason why you ended up with the Divide-By-Zero error is because in this case, the item['goalsAgainst'] in Line...
Read more >ZeroDivisionError division by zero in Python error handling
If you are working in Python, and receive the following output, your code is attempting to divide a given number by zero. ZeroDivisionError....
Read more >ZeroDivisionError: float division - Support - Brian simulator
py extension and treat it as a normal zipped file. I believe the error lies in the differential equations (i.e. HH_equations.py) for the...
Read more >Python Exception Handling - Try/Except Block, Finally Block
ZeroDivisionError: division by zero. During handling of the above exception, another exception occurred: Output. Traceback (most recent call last):File ...
Read more >How to fix Python KeyError Exceptions in simple steps?
In this example, the zipfile.ZipFile class is used to derive information about a ZIP archive 'Batman' using the getinfo() function.
Read more >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
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]
Ah found a more robust workaround: specifying
chunk_size
in the call toiter_bytes
makes it avoid the zero length chunk that stream-unzip doesn’t handle: