Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Refactored chunking loop #44

Merged
merged 1 commit into from
May 7, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading