oconnor663 / blake3-py

Python bindings for the BLAKE3 cryptographic hash function
Other
139 stars 12 forks source link

Feature: accept memoryview besides bytes #9

Closed maartenbreddels closed 3 years ago

maartenbreddels commented 3 years ago

Hi,

thanks for this library, I was looking for something like blake3, so when I found it and found out there was a Python binding, that made me very happy :).

I was wondering if it would be simple to support memoryview instead of bytes. You can get a memoryview on a bytes object, so that would allow for less memory copies if I am not mistaken. Having a memoryview, and converting it to a bytes object (mv.tobytes()) does seem to do a memory copy.

Regards,

Maarten

oconnor663 commented 3 years ago

There should already be support for memoryview. We test it here. Have you given it a try?

maartenbreddels commented 3 years ago

Strange, I'll investigate tomorrow why I got these failures.

oconnor663 commented 3 years ago

Please do. I'll be curious to see the error messages. In the meantime, I've pushed b69d1ba to add a small comment about this to the readme example.

oconnor663 commented 3 years ago

This auto closed because of my commit message, but I do want to test it. The easiest way to import the local build is to do:

$ cd blake3-py/test
$ ./build.py
...
$ python
>>> import blake3
>>> blake3.__file__
'[path to your blake3-py clone]/tests/blake3.so'

I've checked that pyarrow seems to work with my latest changes on master, but please let me know if you have time to repro.