-
-
Notifications
You must be signed in to change notification settings - Fork 8
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
Support de/compress_into(ptr, len)
#23
Comments
@martindurant will something like this work for you? >>> import numpy as np
>>> from cramjam import snappy
>>> values = np.zeros(100, dtype=np.uint8)
>>> snappy.compress_into(b"bytes", values)
>>> values
array([255, 6, 0, 0, 115, 78, 97, 80, 112, 89, 1, 9, 0,
0, 181, 139, 168, 219, 98, 121, 116, 101, 115, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0, 0], dtype=uint8)
>>> values.tobytes()
b'\xff\x06\x00\x00sNaPpY\x01\t\x00\x00\xb5\x8b\xa8\xdbbytes\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\
x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00' then |
Yes, perfect. In practice, I only expect to use Am I right in assuming that the zero padding you have if the length isn't exactly right would cause the decompress to panic? |
Ok, when prototyping that, felt like one might have wanted to and yes, just noticed that myself, should probably return the number of bytes written. Good catch. Most of the de/compression APIs implement the std::io::Read, meaning that if passed a slice, we can read the input which will de/encode until it reaches the end of the output buffer. While a So long as it successfully gets the references, it would not panic, regardless if the output buffer was too short, or too long. |
There's no particular reason to handle this on the rust side, since making a slice/view/memoryview on the python side is no-copy, almost zero-cost. More a case of idle curiosity. Probably needs just a couple of comments in the eventual test-suite - i.e., we'll get the number of bytes back at compression, and then slice the resultant data for decompression and get the original back. |
de/compress directly into a Python buffer
The text was updated successfully, but these errors were encountered: