Reputation: 11
I have a Python program that downloads/streams data using requests.get and decompresses it on the fly using zstd stream_reader.
It's possible that the stream closes or is closed by the user. In these cases, I want the user to be able to continue where they left off, without needing to download and decompress everything up until that point again.
Is it possible, before closing, to store the context of the stream_reader and then start a new get request from that byte, keeping the zstd context?
Starting a new request from byte x and initializing a new stream_reader with that request as a source does not work, since we are not starting from a valid zstd frame.
"Overwriting" only the request/source does not work either. I verified that by closing the initial request and then opening a new one from byte x. stream_reader.read(read_size) will now print empty bytes. (Curiously, when not closing the initial request.get(), it will keep reading from it even though we "overwrote" it with the new one.)
Is there a way to "checkpoint" the stream_reader and initialize it with a new source, but with the context it already has?
This feature seems very important since the files the user downloads/decompresses/processes are very big, so stopping and continuing is a rather necessary functionality.
Upvotes: 1
Views: 41