Skip to content

Commit

Permalink
Implement tell for async stream reader (#741)
Browse files Browse the repository at this point in the history
  • Loading branch information
martindurant committed May 26, 2023
1 parent 42c3e9c commit 676b7b6
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 1 deletion.
5 changes: 4 additions & 1 deletion s3fs/core.py
Original file line number Diff line number Diff line change
Expand Up @@ -2295,13 +2295,16 @@ def __init__(self, fs, path, mode):
self.path = path
self.mode = mode
self.r = None
self.loc = 0

async def read(self, length=-1):
if self.r is None:
bucket, key, gen = self.fs.split_path(self.path)
r = await self.fs._call_s3("get_object", Bucket=bucket, Key=key)
self.r = r["Body"]
return await self.r.read(length)
out = await self.r.read(length)
self.loc += len(out)
return out


def _fetch_range(fs, bucket, key, version_id, start, end, req_kw=None):
Expand Down
1 change: 1 addition & 0 deletions s3fs/tests/test_s3fs.py
Original file line number Diff line number Diff line change
Expand Up @@ -2614,6 +2614,7 @@ async def read_stream():
f = await fs.open_async(fn, mode="rb", block_seze=1000)
while True:
got = await f.read(1000)
assert f.tell()
if not got:
break
out.append(got)
Expand Down

0 comments on commit 676b7b6

Please sign in to comment.