Skip to content

Commit 22f8ea1

Browse files
authored
Let async file know its size after first read (#745)
* Let async file know its size after first read * initial size to None
1 parent 61f96e1 commit 22f8ea1

File tree

2 files changed

+3
-0
lines changed

2 files changed

+3
-0
lines changed

s3fs/core.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2296,11 +2296,13 @@ def __init__(self, fs, path, mode):
22962296
self.mode = mode
22972297
self.r = None
22982298
self.loc = 0
2299+
self.size = None
22992300

23002301
async def read(self, length=-1):
23012302
if self.r is None:
23022303
bucket, key, gen = self.fs.split_path(self.path)
23032304
r = await self.fs._call_s3("get_object", Bucket=bucket, Key=key)
2305+
self.size = int(r["ResponseMetadata"]["HTTPHeaders"]["content-length"])
23042306
self.r = r["Body"]
23052307
out = await self.r.read(length)
23062308
self.loc += len(out)

s3fs/tests/test_s3fs.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2614,6 +2614,7 @@ async def read_stream():
26142614
f = await fs.open_async(fn, mode="rb", block_seze=1000)
26152615
while True:
26162616
got = await f.read(1000)
2617+
assert f.size == len(data)
26172618
assert f.tell()
26182619
if not got:
26192620
break

0 commit comments

Comments
 (0)