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