Python's BytesIO objects offer memory-efficient ways to handle in-memory byte data through getvalue() and getbuffer() methods, avoiding the memory-doubling effect of read(). The getvalue() method uses copy-on-write functionality for optimal memory usage when reading data, while getbuffer() provides a zero-copy memoryview option with some limitations.
https://pythonspeed.com/articles/bytesio-reduce-memory-usage/