From f5c4b477e5025b392ce92ef9bd03c475ab8c4ea0 Mon Sep 17 00:00:00 2001 From: Tulir Asokan Date: Sun, 24 Jun 2018 00:09:44 +0300 Subject: [PATCH] Remove custom download_file_bytes() function --- mautrix_telegram/tgclient.py | 17 ----------------- mautrix_telegram/util/file_transfer.py | 4 ++-- 2 files changed, 2 insertions(+), 19 deletions(-) diff --git a/mautrix_telegram/tgclient.py b/mautrix_telegram/tgclient.py index 273e08b4..302515d8 100644 --- a/mautrix_telegram/tgclient.py +++ b/mautrix_telegram/tgclient.py @@ -14,8 +14,6 @@ # # You should have received a copy of the GNU Affero General Public License # along with this program. If not, see . -from io import BytesIO - from telethon import TelegramClient, utils from telethon.tl.functions.messages import SendMediaRequest from telethon.tl.types import * @@ -42,18 +40,3 @@ class MautrixTelegramClient(TelegramClient): request = SendMediaRequest(entity, media, message=caption or "", entities=entities or [], reply_to_msg_id=reply_to) return self._get_response_message(request, await self(request), entity) - - async def download_file_bytes(self, location): - if isinstance(location, Document): - location = InputDocumentFileLocation(location.id, location.access_hash, - location.version) - elif not isinstance(location, (InputFileLocation, InputDocumentFileLocation)): - location = InputFileLocation(location.volume_id, location.local_id, location.secret) - - file = BytesIO() - - await self.download_file(location, file) - - data = file.getvalue() - file.close() - return data diff --git a/mautrix_telegram/util/file_transfer.py b/mautrix_telegram/util/file_transfer.py index 14c69791..a75b7063 100644 --- a/mautrix_telegram/util/file_transfer.py +++ b/mautrix_telegram/util/file_transfer.py @@ -115,7 +115,7 @@ async def transfer_thumbnail_to_matrix(client, intent, thumbnail_loc, video, mim return None mime_type = "image/png" else: - file = await client.download_file_bytes(thumbnail_loc) + file = await client.download_file(thumbnail_loc) width, height = None, None mime_type = magic.from_buffer(file, mime=True) @@ -155,7 +155,7 @@ async def _unlocked_transfer_file_to_matrix(db, client, intent, id, location, th return db_file try: - file = await client.download_file_bytes(location) + file = await client.download_file(location) except LocationInvalidError: return None except (AuthBytesInvalidError, AuthKeyInvalidError, SecurityError) as e: