Path: csiph.com!optima2.xanadu-bbs.net!xanadu-bbs.net!feeder.erje.net!1.eu.feeder.erje.net!bcyclone04.am1.xlned.com!bcyclone04.am1.xlned.com!newsfeed.xs4all.nl!newsfeed7.news.xs4all.nl!post.news.xs4all.nl!not-for-mail Return-Path: X-Original-To: python-list@python.org Delivered-To: python-list@mail.python.org X-Spam-Status: OK 0.002 X-Spam-Evidence: '*H*': 1.00; '*S*': 0.00; 'subject:Python': 0.05; 'binary': 0.05; 'data:': 0.07; 'subject:file': 0.07; 'eat': 0.09; 'chunks.': 0.16; 'from:addr:cs': 0.16; 'from:addr:zip.com.au': 0.16; 'from:name:cameron simpson': 0.16; 'message- id:@cskk.homeip.net': 0.16; 'received:211.29': 0.16; 'received:211.29.132': 0.16; 'received:cskk.homeip.net': 0.16; 'received:homeip.net': 0.16; 'received:optusnet.com.au': 0.16; 'received:syd.optusnet.com.au': 0.16; 'simpson': 0.16; 'subject:download': 0.16; 'true:': 0.16; 'wrote:': 0.16; 'first.': 0.18; 'cheers,': 0.24; 'header:In-Reply-To:1': 0.24; 'example': 0.25; 'header:User-Agent:1': 0.26; 'jim': 0.27; "i'm": 0.29; 'http': 0.33; 'received:com.au': 0.33; 'to:addr:python-list': 0.35; 'files,': 0.35; 'skip:o 20': 0.35; 'but': 0.36; 'subject:: ': 0.37; 'charset:us-ascii': 0.37; 'to:addr:python.org': 0.39; 'data': 0.40; 'content-disposition:inline': 0.60; 'email addr:gmail.com': 0.64; 'here': 0.66; 'cameron': 0.66; 'life': 0.66; 'talking': 0.67; 'worth': 0.73; 'otten': 0.84 Date: Thu, 2 Jul 2015 08:50:10 +1000 From: Cameron Simpson To: python-list@python.org Subject: Re: Python 3 resuma a file download MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii; format=flowed Content-Disposition: inline In-Reply-To: User-Agent: Mutt/1.5.23 (2014-03-12) References: X-Optus-CM-Score: 0 X-Optus-CM-Analysis: v=2.1 cv=eZjABOwH c=1 sm=1 tr=0 a=rgDbx50tNA2z7xLXQOoruw==:117 a=rgDbx50tNA2z7xLXQOoruw==:17 a=ZtCCktOnAAAA:8 a=PO7r1zJSAAAA:8 a=vrnE16BAAAAA:8 a=yEdEr6MRgwAA:10 a=kj9zAlcOel0A:10 a=zOBTXjUuO1YA:10 a=pGLkceISAAAA:8 a=bbMSHy_Gu62Kz6CStQ4A:9 a=CjuIK1q_8ugA:10 X-BeenThere: python-list@python.org X-Mailman-Version: 2.1.20+ Precedence: list List-Id: General discussion list for the Python programming language List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Newsgroups: comp.lang.python Message-ID: Lines: 28 NNTP-Posting-Host: 2001:888:2000:d::a6 X-Trace: 1435792055 news.xs4all.nl 2876 [2001:888:2000:d::a6]:37151 X-Complaints-To: abuse@xs4all.nl X-Received-Bytes: 3626 X-Received-Body-CRC: 204408117 Xref: csiph.com comp.lang.python:93393 On 01Jul2015 21:51, Peter Otten <__peter__@web.de> wrote: >zljubisic@gmail.com wrote: > >> But how to read chunks? > >Instead of > >> data = response.read() # a `bytes` object >> out_file.write(data) > >use a loop: > >CHUNKSIZE = 16*1024 # for example >while True: > data = response.read(CHUNKSIZE) > if not data: > break > out_file.write(data) It might be worth noting here that Peter's "chunk" is just an arbitrary amount of data to read in a unit. I'm only mentioning this because the HTTP specification has a "chunked-encoding" used to return binary files, and we are not talking about _those_ chunks. Cheers, Cameron Simpson Life is uncertain. Eat dessert first. - Jim Blandy