Add seek_begin keyword argument to Attachment.save
This commit is contained in:
parent
9d3d8e0f0a
commit
355eb08b25
@ -72,7 +72,7 @@ class Attachment:
|
|||||||
self._http = state.http
|
self._http = state.http
|
||||||
|
|
||||||
@asyncio.coroutine
|
@asyncio.coroutine
|
||||||
def save(self, fp):
|
def save(self, fp, *, seek_begin=True):
|
||||||
"""|coro|
|
"""|coro|
|
||||||
|
|
||||||
Saves this attachment into a file-like object.
|
Saves this attachment into a file-like object.
|
||||||
@ -83,6 +83,9 @@ class Attachment:
|
|||||||
The file-like object to save this attachment to or the filename
|
The file-like object to save this attachment to or the filename
|
||||||
to use. If a filename is passed then a file is created with that
|
to use. If a filename is passed then a file is created with that
|
||||||
filename and used instead.
|
filename and used instead.
|
||||||
|
seek_begin: bool
|
||||||
|
Whether to seek to the beginning of the file after saving is
|
||||||
|
successfully done.
|
||||||
|
|
||||||
Raises
|
Raises
|
||||||
--------
|
--------
|
||||||
@ -102,7 +105,10 @@ class Attachment:
|
|||||||
with open(fp, 'wb') as f:
|
with open(fp, 'wb') as f:
|
||||||
return f.write(data)
|
return f.write(data)
|
||||||
else:
|
else:
|
||||||
return fp.write(data)
|
written = fp.write(data)
|
||||||
|
if seek_begin:
|
||||||
|
fp.seek(0)
|
||||||
|
return written
|
||||||
|
|
||||||
class Message:
|
class Message:
|
||||||
"""Represents a message from Discord.
|
"""Represents a message from Discord.
|
||||||
|
Loading…
x
Reference in New Issue
Block a user