iSoFe commited on
Commit
e2afcfa
·
verified ·
1 Parent(s): e3bce8f

Update bot.py

Browse files
Files changed (1) hide show
  1. bot.py +6 -5
bot.py CHANGED
@@ -4,7 +4,6 @@ import asyncio
4
  import logging
5
  import tempfile
6
  import aiohttp
7
- import aiofiles
8
  from collections import defaultdict
9
  from pyrogram import Client, filters
10
  from pyrogram.types import Message
@@ -183,26 +182,28 @@ class ProgressTracker:
183
 
184
 
185
  class TrackingFileReader:
186
- """قارئ ملف يتابع البايتات المرسلة لحساب التقدم"""
187
 
188
  def __init__(self, path: str, tracker: ProgressTracker):
189
  self._path = path
190
  self._tracker = tracker
191
  self._file = None
 
192
 
193
  async def __aenter__(self):
194
- self._file = await aiofiles.open(self._path, "rb")
 
195
  return self
196
 
197
  async def __aexit__(self, *_):
198
  if self._file:
199
- await self._file.close()
200
 
201
  def __aiter__(self):
202
  return self
203
 
204
  async def __anext__(self) -> bytes:
205
- chunk = await self._file.read(CHUNK_SIZE)
206
  if not chunk:
207
  raise StopAsyncIteration
208
  await self._tracker.add(len(chunk))
 
4
  import logging
5
  import tempfile
6
  import aiohttp
 
7
  from collections import defaultdict
8
  from pyrogram import Client, filters
9
  from pyrogram.types import Message
 
182
 
183
 
184
  class TrackingFileReader:
185
+ """قارئ ملف يتابع البايتات المرسلة — بدون مكتبات خارجية"""
186
 
187
  def __init__(self, path: str, tracker: ProgressTracker):
188
  self._path = path
189
  self._tracker = tracker
190
  self._file = None
191
+ self._loop = None
192
 
193
  async def __aenter__(self):
194
+ self._loop = asyncio.get_event_loop()
195
+ self._file = await self._loop.run_in_executor(None, open, self._path, "rb")
196
  return self
197
 
198
  async def __aexit__(self, *_):
199
  if self._file:
200
+ await self._loop.run_in_executor(None, self._file.close)
201
 
202
  def __aiter__(self):
203
  return self
204
 
205
  async def __anext__(self) -> bytes:
206
+ chunk = await self._loop.run_in_executor(None, self._file.read, CHUNK_SIZE)
207
  if not chunk:
208
  raise StopAsyncIteration
209
  await self._tracker.add(len(chunk))