def replace(self, attachable: [io.BytesIO, io.FileIO], position=None, **kwargs):
"""
.. versionadded:: 0.5
Replace the underlying file-object with a seekable one.
:param attachable: A seekable file-object.
:param position: Position of the new seekable file-object. if :data:`.None`, position will be preserved.
:param kwargs: the same as the :class:`.BaseDescriptor`
"""
if position is None:
position = self.tell()
# Close the old file-like object
self.close()
self._file = attachable
# Some hacks are here:
super().__init__(**kwargs)
self.seek(position)
评论列表
文章目录