Skip to content

Commit

Permalink
Refactored chunking loop
Browse files Browse the repository at this point in the history
  • Loading branch information
FredHaa committed May 7, 2024
1 parent 2cfa717 commit 88b1324
Showing 1 changed file with 4 additions and 6 deletions.
10 changes: 4 additions & 6 deletions src/mediacatch_s2t/uploader.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import requests
from concurrent.futures import ThreadPoolExecutor, as_completed
from io import BufferedReader
from pathlib import Path
from typing import Optional, Generator, Union

Expand Down Expand Up @@ -104,19 +105,16 @@ def upload_file_chunks(self) -> None:
except Exception as e:
print(f"Chunk {part_number} failed to upload due to: {e}")

def _read_file_in_chunks(self, file) -> Generator[bytes, None, None]:
def _read_file_in_chunks(self, file: BufferedReader) -> Generator[bytes, None, None]:
"""Generator that reads the file in chunks.
Args:
file (IO[bytes]): File object opened in binary read mode.
file (BufferedReader): File object opened in binary read mode.
Yields:
bytes: A chunk of the file.
"""
while True:
chunk = file.read(self.CHUNK_SIZE)
if not chunk:
break
while chunk := file.read(self.CHUNK_SIZE):
yield chunk

def upload_chunk(self, part_number: int, chunk: bytes) -> None:
Expand Down

0 comments on commit 88b1324

Please sign in to comment.