[issue17436] hashlib: add a method to hash the content of a file

Aviv Palivoda report at bugs.python.org
Sat Apr 2 10:34:40 EDT 2016


Aviv Palivoda added the comment:

> * hashobj.readfile(filename: str)
> * hashobj.readfileobj(file) where file is an object with a read() method which returns bytes strings

I changed the API to the one Victor suggested.

> For readfile() it might make more sense to implement it directly in C and let OpenSSL's BIO layer handle IO internally. It's more efficient and you can release the GIL around the whole operation.

The readfile method use the openSSL BIO and releases the GIL around the all operation.

> I suggest to look at copyfile() and copyfileobj() functions of the shutil module. For example, copyfileobj() has an optional parameter for the buffer size. You should probably uses that to avoid complex heuristic to guess the optimal buffer size.

Added a block_size optional argument to the readfileobj().

> In readfile(), you know that it's a regular file which exists on the file system. So you can directly uses _Py_fstat() to get st_blksize

Currently using constant block size in readfile(). From the discussion in issue 26488 I am not sure if this should be changed.

----------
Added file: http://bugs.python.org/file42356/17436-2.patch

_______________________________________
Python tracker <report at bugs.python.org>
<http://bugs.python.org/issue17436>
_______________________________________


More information about the Python-bugs-list mailing list