From 2b327ac0fd02321c29eb5d5e788bd7fe90867618 Mon Sep 17 00:00:00 2001 From: Johannes Schauer Marin Rodrigues Date: Wed, 14 Jun 2023 07:34:51 +0200 Subject: [PATCH] caching_proxy.py: add comment about not using shutil.copyfileobj() --- caching_proxy.py | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/caching_proxy.py b/caching_proxy.py index 4bc7b9e..e57a851 100755 --- a/caching_proxy.py +++ b/caching_proxy.py @@ -57,6 +57,8 @@ class ProxyRequestHandler(http.server.BaseHTTPRequestHandler): self.send_header("Content-Length", oldpath.stat().st_size) self.end_headers() with oldpath.open(mode="rb") as old, newpath.open(mode="wb") as new: + # we are not using shutil.copyfileobj() because we want to + # write to two file objects simultaneously while True: buf = old.read(64 * 1024) # same as shutil uses if not buf: @@ -81,6 +83,9 @@ class ProxyRequestHandler(http.server.BaseHTTPRequestHandler): self.send_header(k, v) self.end_headers() with newpath.open(mode="wb") as f: + # we are not using shutil.copyfileobj() because we want to + # write to two file objects simultaneously and throttle the + # writing speed to 1024 kB/s while True: buf = res.read(64 * 1024) # same as shutil uses if not buf: