Message299054
If I'm not mistaken, a BytesIO buffer can be in three states:
(1) `b = BytesIO(b'data')` -> free of any constraints
(2) `d = b'data'; b = BytesIO(d)` -> cannot modify the underlying bytes without copying them
(3) `b = BytesIO(b'data'); d = b.getbuffer()` -> cannot return a "bytes" representation of the data without copying it (the underlying buffer might change)
My use-case is "how to get the length of the data currently in the BytesIO object".
And right now, there are two solutions:
(a) `len(b.getvalue())`
(b) `len(b.getbuffer())`
but, solution (a) is copying data if the buffer is in state (3) ; and solution (b) is copying data for state (2).
And I don't see any way to distinguish between the three states from Python code.
So as far as I understand it, there is no way to get the size of the buffer in Python that would reliably not copy any data
Should I open a PR to add a `size()` method on the BytesIO class? (simply returning `PyLong_FromSsize_t(self->string_size)` |
|
Date |
User |
Action |
Args |
2017-07-25 12:03:58 | rthr | set | recipients:
+ rthr |
2017-07-25 12:03:58 | rthr | set | messageid: <1500984238.01.0.587335781014.issue31025@psf.upfronthosting.co.za> |
2017-07-25 12:03:57 | rthr | link | issue31025 messages |
2017-07-25 12:03:57 | rthr | create | |
|