Created
September 8, 2022 08:36
-
-
Save wfng92/975636f5bcde123cb6bdf9258a2df943 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class Greeter(hello_pb2_grpc.GreeterServicer): | |
def DownloadFile(self, request, context): | |
chunk_size = 1024 | |
filepath = f'{request.filename}{request.extension}' | |
if os.path.exists(filepath): | |
with open(filepath, mode="rb") as f: | |
while True: | |
chunk = f.read(chunk_size) | |
if chunk: | |
entry_response = hello_pb2.FileResponse(chunk_data=chunk) | |
yield entry_response | |
else: # The chunk was empty, which means we're at the end of the file | |
return |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment