Visitar URL original
fix(save-file): fix some problems uncaught during review · hydrogram/hydrogram@0904bd1 · GitHub
Skip to content

Commit 0904bd1

Browse files
fix(save-file): fix some problems uncaught during review
1 parent daba894 commit 0904bd1

1 file changed

Lines changed: 5 additions & 12 deletions

File tree

‎hydrogram/methods/advanced/save_file.py‎

Lines changed: 5 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,6 @@
2323
import io
2424
import logging
2525
import math
26-
import os
2726
from hashlib import md5
2827
from pathlib import Path, PurePath
2928
from typing import BinaryIO, Callable, Optional, Union
@@ -113,28 +112,22 @@ async def worker(session):
113112
part_size = 512 * 1024
114113

115114
if isinstance(path, (str, PurePath)):
116-
with Path(path).open("rb") as fp:
117-
file_size = fp.tell()
118-
fp.seek(0)
119-
120-
if file_size == 0:
121-
raise ValueError("File size equals to 0 B")
115+
fp = Path(path).open("rb") # noqa: SIM115
122116
elif isinstance(path, io.IOBase):
123117
fp = path
124-
file_name = getattr(fp, "name", "file.jpg")
125-
fp.seek(0, os.SEEK_END)
126-
file_size = fp.tell()
127-
fp.seek(0)
128118
else:
129119
raise ValueError(
130120
"Invalid file. Expected a file path as string or a binary (not text) file pointer"
131121
)
122+
132123
file_size = fp.tell()
133-
fp.seek(0)
134124

135125
if file_size == 0:
136126
raise ValueError("File size equals to 0 B")
137127

128+
file_name = getattr(fp, "name", "file.jpg")
129+
fp.seek(0)
130+
138131
file_size_limit_mib = 4000 if self.me.is_premium else 2000
139132

140133
if file_size > file_size_limit_mib * 1024 * 1024:

0 commit comments

Comments
 (0)