Skip to content

Commit

Permalink
Remove redundant streaming in download of file
Browse files Browse the repository at this point in the history
In PR #71 a streaming mechanism has been implemented for the endpoint
`/nodes/{nodes_id}/download`, this however is already taken care by
FastAPI StreamingResponse and is therefore redundant and can be removed.
  • Loading branch information
agoscinski committed Nov 21, 2024
1 parent 366f036 commit ad2772f
Show file tree
Hide file tree
Showing 2 changed files with 1 addition and 6 deletions.
3 changes: 0 additions & 3 deletions aiida_restapi/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,3 @@
'disabled': False,
}
}

# The chunks size for streaming data for download
DOWNLOAD_CHUNK_SIZE = 1024
4 changes: 1 addition & 3 deletions aiida_restapi/routers/nodes.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@
from pydantic import ValidationError

from aiida_restapi import models, resources
from aiida_restapi.config import DOWNLOAD_CHUNK_SIZE

from .auth import get_current_active_user

Expand Down Expand Up @@ -73,8 +72,7 @@ async def download_node(nodes_id: int, download_format: Optional[str] = None) ->

def stream() -> Generator[bytes, None, None]:
with io.BytesIO(exported_bytes) as handler:
while chunk := handler.read(DOWNLOAD_CHUNK_SIZE):
yield chunk
yield from handler

return StreamingResponse(stream(), media_type=f'application/{download_format}')

Expand Down

0 comments on commit ad2772f

Please sign in to comment.