This issue tracker has been migrated to GitHub, and is currently read-only.
For more information, see the GitHub FAQs in the Python's Developer Guide.

Author Aur.Saraf
Recipients Aur.Saraf, christian.heimes, gregory.p.smith, python-dev, tarek
Date 2022-03-16.18:51:44
SpamBayes Score -1.0
Marked as misclassified Yes
Message-id <1647456704.46.0.481208606987.issue45150@roundup.psfhosted.org>
In-reply-to
Content
I don't think HMAC of a file is a common enough use case to support, but I have absolutely no problem conceding this point, the cost of supporting it is very low.

I/O in C is a world of pain in general. In the specific case of `io.RawIOBase` objects (non-buffered binary files) to my understanding it's not _that_ terrible (am I right? Does my I/O code work as-is?). To my understanding, providing a fast path *just for this case* that calculates the hash without taking the GIL for every chunk would be very nice to have for many use cases.

Now, we could just be happy with `file_digest()` having an `if` for `isinstance(io.RawIOBase)` that chooses a fast code path silently. But since non-buffered binary files are so hard to tell apart from other types of file-like objects, as a user of this code I would like to have a way to say "I want the fast path, please raise if I accidentally passed the wrong things and got the regular path". We could have `file_digest('sha256', open(path, 'rb', buffered=0), ensure_fast_io=True)`, but I think for this use case `raw_file_digest('sha256', open(path, 'rb', buffered=0))` is cleaner.

In all other cases you just call `file_digest()`, probably get the Python I/O and not the C I/O, and are still happy to have that loop written for you by someone who knows what they're doing.

For the same reason I think the fast path should only support hash names and not constructors/functions/etc', which would complicate it because new-object-can-be-accessed-without-GIL wouldn't necessarily apply.

Does this make sense?
History
Date User Action Args
2022-03-16 18:51:44Aur.Sarafsetrecipients: + Aur.Saraf, gregory.p.smith, christian.heimes, tarek, python-dev
2022-03-16 18:51:44Aur.Sarafsetmessageid: <1647456704.46.0.481208606987.issue45150@roundup.psfhosted.org>
2022-03-16 18:51:44Aur.Saraflinkissue45150 messages
2022-03-16 18:51:44Aur.Sarafcreate