refactor: update load_stream method to directly yield file chunks (#9806)

This commit is contained in:
zhuhao
2024-10-25 10:11:25 +08:00
committed by GitHub
parent dd17506078
commit 5bf31e7a86
11 changed files with 48 additions and 83 deletions

View File

@@ -40,15 +40,11 @@ class LocalFsStorage(BaseStorage):
def load_stream(self, filename: str) -> Generator:
filepath = self._build_filepath(filename)
def generate() -> Generator:
if not os.path.exists(filepath):
raise FileNotFoundError("File not found")
with open(filepath, "rb") as f:
while chunk := f.read(4096): # Read in chunks of 4KB
yield chunk
return generate()
if not os.path.exists(filepath):
raise FileNotFoundError("File not found")
with open(filepath, "rb") as f:
while chunk := f.read(4096): # Read in chunks of 4KB
yield chunk
def download(self, filename, target_filepath):
filepath = self._build_filepath(filename)