How do I implement a FIFO buffer to which I can efficiently add arbitrarily sized chunks of bytes to the head and from which I can efficiently pop arbitrarily sized chunks of by
I have currently implemented this with a StringIO object. Writing new bytes to the end of the StringIO object is fast, but removing bytes from the beginning is very slow, because a new StringIO object, that holds a copy of the entire previous buffer minus the first chunk of bytes, must be created.
Actually the most typical way of implementing FIFO is two use wrap around buffer with two pointers as such:
image source
Now, you can implement that with StringIO()
using .seek() to read/write from appropriate location.