-
Notifications
You must be signed in to change notification settings - Fork 16
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
Filesize detection doesn't work for compressed files #50
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM, but what's the special meaning of 1024 bytes here? Where does this number come from? A comment in the code would be helpful.
I have no idea where the 1024 bytes came from. I suspect that it wasn't considered too useful to find a boundary chunk if the file is too close to the end, but how the 1024 came from that I don't know. |
Can you add this explanation as a comment (it makes sense to not look for boundary chunks very close to the end of a file)? |
It doesn't matter how much data is left, so I changed the check to read only one byte. If there's not enough left for a boundary chunk, |
And this happens only for corrupt files anyway, right? |
Yes with a tiny bit of fineprint. For regular files it shouldn't happen. |
pyxdf/pyxdf.py
Outdated
f.seek(-1, 1) | ||
if _scan_forward(f): | ||
continue | ||
else: |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I guess you could get rid of this else: break
block because you have the same thing right in the next else
block. I.e. I think you can remove the first else
block completely (the one belonging to the if _scan_forward(f)
), and also remove the second else
and dedent the two subsequent lines.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Right, I've changed it.
Thanks @tstenner! |
https://github.com/xdf-modules/xdf-python/blob/a6c5f84860c41de9d63fc3f66ac7cac0f7779bc7/pyxdf/pyxdf.py#L235-L245
For compressed files, reading the file is aborted as soon as an invalid chunk size is read and the position in the uncompressed stream is after the compressed size. So, the new code checks if more than 1024 bytes are actually readable.