I'd like to use 2 stream pointers within a stream, and position the 2 pointers at different positions. How do I make a copy of the first stream, so that the copy doesn't mirror the state of the first stream, from this point in time?
In particular, I'm interested in streams of the type io.BytesIO()
import io
stream1 = open("Input.jpg", "rb")
stream2 = stream1
print('A', stream1.tell(), stream2.tell())
stream1.seek(10)
print('B', stream1.tell(), stream2.tell())
My goal is to see output of
A 0 0
B 10 0
However, I see
A 0 0
B 10 10
@varela Thanks for the response. Unfortunately, this doesn't work well when the stream doesn't have a file descriptor (which can happen if we don't open a file). For example, instead of stream1=open("Input.jpg", "rb")
stream1 = io.BytesIO() image.save(stream1, format='JPEG')
Any suggestions on how to handle this case?
Thanks.