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 rthr
Recipients rthr
Date 2017-07-25.12:03:57
SpamBayes Score -1.0
Marked as misclassified Yes
Message-id <1500984238.01.0.587335781014.issue31025@psf.upfronthosting.co.za>
In-reply-to
Content
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)`
History
Date User Action Args
2017-07-25 12:03:58rthrsetrecipients: + rthr
2017-07-25 12:03:58rthrsetmessageid: <1500984238.01.0.587335781014.issue31025@psf.upfronthosting.co.za>
2017-07-25 12:03:57rthrlinkissue31025 messages
2017-07-25 12:03:57rthrcreate