From: Michael Tremer Date: Sun, 4 Dec 2016 22:56:51 +0000 (+0100) Subject: http: Actually write downloaded files to the filesystem X-Git-Tag: 0.9.28~1285^2~1403 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=b34939e073540496b6d3051aab647c3148d25889;p=pakfire.git http: Actually write downloaded files to the filesystem Signed-off-by: Michael Tremer --- diff --git a/src/pakfire/http.py b/src/pakfire/http.py index de8065837..944110de1 100644 --- a/src/pakfire/http.py +++ b/src/pakfire/http.py @@ -227,19 +227,23 @@ class Client(object): # Send the request with self._make_progressbar(message) as p: - with self._send_request(r) as f: - # Try setting progress bar to correct maximum value - # XXX this might need a function in ProgressBar - l = self._get_content_length(f) - p.value_max = l - - while True: - buf = f.read(buffer_size) - if not buf: - break - - l = len(buf) - p.increment(l) + with open(filename, "wb") as f: + with self._send_request(r) as res: + # Try setting progress bar to correct maximum value + # XXX this might need a function in ProgressBar + l = self._get_content_length(res) + p.value_max = l + + while True: + buf = res.read(buffer_size) + if not buf: + break + + # Write downloaded data to file + f.write(buf) + + l = len(buf) + p.increment(l) def _get_content_length(self, response): s = response.getheader("Content-Length")