Skip to content

Commit 542c8cf

Browse files
committed
upip: save_file(): Optimize, use inplace buffer.
1 parent 7bc041e commit 542c8cf

File tree

1 file changed

+9
-7
lines changed

1 file changed

+9
-7
lines changed

upip/upip.py

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,8 @@
1111
debug = False
1212
cleanup_files = []
1313

14+
file_buf = bytearray(512)
15+
1416
class NotFoundError(Exception):
1517
pass
1618

@@ -44,13 +46,13 @@ def _makedirs(name, mode=0o777):
4446

4547

4648
def save_file(fname, subf):
47-
outf = open(fname, "wb")
48-
while True:
49-
buf = subf.read(1024)
50-
if not buf:
51-
break
52-
outf.write(buf)
53-
outf.close()
49+
global file_buf
50+
with open(fname, "wb") as outf:
51+
while True:
52+
sz = subf.readinto(file_buf)
53+
if not sz:
54+
break
55+
outf.write(file_buf, sz)
5456

5557
def install_tar(f, prefix):
5658
meta = {}

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy