kopia lustrzana https://github.com/micropython/micropython-lib
shutil: copyfileobj(): Support file objects without readinto() method.
rodzic
94b2afdf8b
commit
f3dd9abcda
|
@ -9,13 +9,20 @@ def rmtree(top):
|
||||||
os.rmdir(path)
|
os.rmdir(path)
|
||||||
|
|
||||||
def copyfileobj(src, dest, length=512):
|
def copyfileobj(src, dest, length=512):
|
||||||
buf = bytearray(length)
|
if hasattr(src, "readinto"):
|
||||||
while True:
|
buf = bytearray(length)
|
||||||
sz = src.readinto(buf)
|
while True:
|
||||||
if not sz:
|
sz = src.readinto(buf)
|
||||||
break
|
if not sz:
|
||||||
if sz == length:
|
break
|
||||||
|
if sz == length:
|
||||||
|
dest.write(buf)
|
||||||
|
else:
|
||||||
|
b = memoryview(buf)[:sz]
|
||||||
|
dest.write(b)
|
||||||
|
else:
|
||||||
|
while True:
|
||||||
|
buf = src.read(length)
|
||||||
|
if not buf:
|
||||||
|
break
|
||||||
dest.write(buf)
|
dest.write(buf)
|
||||||
else:
|
|
||||||
b = memoryview(buf)[:sz]
|
|
||||||
dest.write(b)
|
|
||||||
|
|
Ładowanie…
Reference in New Issue