How can pickled byte data be resolved?
How can I write and read pickled data from a BytesIO object?
I tried:
import io
import cPickle as pickle
s1 = "foo"
bytes_io = io.BytesIO()
pickle.dump(s1, bytes_io, pickle.HIGHEST_PROTOCOL)
s2 = pickle.load(bytes_io)
which gives for the pickle.load line:
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
EOFError
+3
user3921265
source
to share
1 answer
You just haven't rewound your buffer: bytes_io.seek(0)
to pickle.load
.
You might not want to rewind back to the edge of the buffer, but only to the beginning of your pickled data. Then read the flow position bytes_io.tell()
before etching and find that position instead 0
.
+4
source to share