kopia lustrzana https://github.com/micropython/micropython-lib
upip: save_file(): Optimize, use inplace buffer.
rodzic
7bc041e620
commit
542c8cf9ef
12
upip/upip.py
12
upip/upip.py
|
@ -11,6 +11,8 @@ DEFAULT_MICROPYPATH = "~/.micropython/lib:/usr/lib/micropython"
|
||||||
debug = False
|
debug = False
|
||||||
cleanup_files = []
|
cleanup_files = []
|
||||||
|
|
||||||
|
file_buf = bytearray(512)
|
||||||
|
|
||||||
class NotFoundError(Exception):
|
class NotFoundError(Exception):
|
||||||
pass
|
pass
|
||||||
|
|
||||||
|
@ -44,13 +46,13 @@ def _makedirs(name, mode=0o777):
|
||||||
|
|
||||||
|
|
||||||
def save_file(fname, subf):
|
def save_file(fname, subf):
|
||||||
outf = open(fname, "wb")
|
global file_buf
|
||||||
|
with open(fname, "wb") as outf:
|
||||||
while True:
|
while True:
|
||||||
buf = subf.read(1024)
|
sz = subf.readinto(file_buf)
|
||||||
if not buf:
|
if not sz:
|
||||||
break
|
break
|
||||||
outf.write(buf)
|
outf.write(file_buf, sz)
|
||||||
outf.close()
|
|
||||||
|
|
||||||
def install_tar(f, prefix):
|
def install_tar(f, prefix):
|
||||||
meta = {}
|
meta = {}
|
||||||
|
|
Ładowanie…
Reference in New Issue