Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.lang.python > #93393

Re: Python 3 resuma a file download

Date 2015-07-02 08:50 +1000
From Cameron Simpson <cs@zip.com.au>
Subject Re: Python 3 resuma a file download
References <mn1gct$nb0$1@ger.gmane.org>
Newsgroups comp.lang.python
Message-ID <mailman.228.1435792055.3674.python-list@python.org> (permalink)

Show all headers | View raw


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 <cs@zip.com.au>

Life is uncertain.  Eat dessert first.  - Jim Blandy

Back to comp.lang.python | Previous | Next | Find similar | Unroll thread


Thread

Re: Python 3 resuma a file download Cameron Simpson <cs@zip.com.au> - 2015-07-02 08:50 +1000

csiph-web