Remove fake_start

master
blank X 1 year ago
parent 02ad4d6d6b
commit d0d7009886
Signed by: blankie
GPG Key ID: CC15FC822C7F61F5
  1. 9
      autoytarchive/cappedio.py
  2. 6
      autoytarchive/workers.py

@ -2,10 +2,9 @@ import io
import os
class CappedBufferedReader(io.BufferedReader):
def __init__(self, raw, buffer_size=io.DEFAULT_BUFFER_SIZE, capped_size=None, fake_start=None):
def __init__(self, raw, buffer_size=io.DEFAULT_BUFFER_SIZE, capped_size=None):
super().__init__(raw, buffer_size)
self.capped_size = capped_size
self.fake_start = fake_start
def read(self, size=None):
if self.capped_size is not None:
@ -25,8 +24,6 @@ class CappedBufferedReader(io.BufferedReader):
else:
offset = self.capped_size
whence = os.SEEK_SET
elif whence == os.SEEK_SET and self.fake_start is not None:
offset += self.fake_start
return super().seek(offset, whence)
@property
@ -40,5 +37,5 @@ class CappedBufferedReader(io.BufferedReader):
def name(self, new_name):
self._name = new_name
def bopen(file, capped_size, fake_start):
return CappedBufferedReader(open(file, 'rb', buffering=0), capped_size=capped_size, fake_start=fake_start)
def bopen(file, capped_size):
return CappedBufferedReader(open(file, 'rb', buffering=0), capped_size=capped_size)

@ -228,9 +228,9 @@ async def _upload_worker():
is_big = total_size > size_limit
files_sent = size_sent = 0
messages = []
file = bopen(video_filename, size_limit, None)
file = bopen(video_filename, size_limit)
while total_size > 0:
file.fake_start = size_sent
file.seek(size_sent)
if is_big:
file.name = f'{base_filename}.part{str(files_sent).rjust(2, "0")}'
messages.append((await client.send_message(config['config']['storage_chat_id'], f'Uploading {file.name}...', parse_mode=None)).id)
@ -239,7 +239,7 @@ async def _upload_worker():
if total_size > 0:
size_sent += message.document.size
files_sent += 1
file = bopen(video_filename, size_limit, None)
file = bopen(video_filename, size_limit)
if messages:
await client.delete_messages(config['config']['storage_chat_id'], messages)
finally:

Loading…
Cancel
Save