Skip to content

Commit bdaf5aa

Browse files
authored
Make put_file continue on zero-read (#869)
* Make put_file continue on zero-read * fix test
1 parent b45ae3e commit bdaf5aa

File tree

2 files changed

+6
-4
lines changed

2 files changed

+6
-4
lines changed

fsspec/spec.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -803,13 +803,13 @@ def put_file(self, lpath, rpath, callback=_DEFAULT_CALLBACK, **kwargs):
803803
return None
804804

805805
with open(lpath, "rb") as f1:
806-
callback.set_size(f1.seek(0, 2))
806+
size = f1.seek(0, 2)
807+
callback.set_size(size)
807808
f1.seek(0)
808809

809810
self.mkdirs(self._parent(os.fspath(rpath)), exist_ok=True)
810811
with self.open(rpath, "wb", **kwargs) as f2:
811-
data = True
812-
while data:
812+
while f2.tell() < size:
813813
data = f1.read(self.blocksize)
814814
segment_len = f2.write(data)
815815
callback.relative_update(segment_len)

fsspec/tests/test_spec.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -495,7 +495,9 @@ def test_dummy_callbacks_file(tmpdir):
495495
source.write_text("x" * 100, "utf-8")
496496

497497
fs.put_file(source, file, callback=callback)
498-
assert callback.events == imitate_transfer(size, 10)
498+
499+
# -1 here since put_file no longer has final zero-size put
500+
assert callback.events == imitate_transfer(size, 10)[:-1]
499501
callback.events.clear()
500502

501503
fs.get_file(file, destination, callback=callback)

0 commit comments

Comments
 (0)