Skip to content

Commit

Permalink
Add whence parameter to UploadFile.seek()
Browse files Browse the repository at this point in the history
  • Loading branch information
dvarrazzo committed Nov 1, 2020
1 parent 7a783d3 commit 7a7d2e3
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 4 deletions.
6 changes: 3 additions & 3 deletions starlette/datastructures.py
Expand Up @@ -449,11 +449,11 @@ async def read(self, size: int = -1) -> typing.Union[bytes, str]:
return self.file.read(size)
return await run_in_threadpool(self.file.read, size)

async def seek(self, offset: int) -> None:
async def seek(self, offset: int, whence: int) -> None:
if self._in_memory:
self.file.seek(offset)
self.file.seek(offset, whence)
else:
await run_in_threadpool(self.file.seek, offset)
await run_in_threadpool(self.file.seek, offset, whence)

async def close(self) -> None:
if self._in_memory:
Expand Down
2 changes: 1 addition & 1 deletion tests/test_datastructures.py
Expand Up @@ -222,7 +222,7 @@ async def test_upload_file():
big_file = BigUploadFile("big-file")
await big_file.write(b"big-data" * 512)
await big_file.write(b"big-data")
await big_file.seek(0)
await big_file.seek(0, 0)
assert await big_file.read(1024) == b"big-data" * 128
await big_file.close()

Expand Down

0 comments on commit 7a7d2e3

Please sign in to comment.