Package googleapiclient :: Module http :: Class MediaIoBaseDownload
[hide private]
[frames] | no frames]

Class MediaIoBaseDownload

source code


"Download media resources.

Note that the Python file object is compatible with io.Base and can be used
with this class also.


Example:
  request = farms.animals().get_media(id='cow')
  fh = io.FileIO('cow.png', mode='wb')
  downloader = MediaIoBaseDownload(fh, request, chunksize=1024*1024)

  done = False
  while done is False:
    status, done = downloader.next_chunk()
    if status:
      print "Download %d%%." % int(status.progress() * 100)
  print "Download Complete!"

Instance Methods [hide private]
 
__init__(self, fd, request, chunksize=DEFAULT_CHUNK_SIZE)
Constructor.
source code
 
next_chunk(self, num_retries=0)
Get the next chunk of the download.
source code

Inherited from object: __delattr__, __format__, __getattribute__, __hash__, __new__, __reduce__, __reduce_ex__, __repr__, __setattr__, __sizeof__, __str__, __subclasshook__

Properties [hide private]

Inherited from object: __class__

Method Details [hide private]

__init__(self, fd, request, chunksize=DEFAULT_CHUNK_SIZE)
(Constructor)

source code 
Constructor.

Args:
  fd: io.Base or file object, The stream in which to write the downloaded
    bytes.
  request: googleapiclient.http.HttpRequest, the media request to perform in
    chunks.
  chunksize: int, File will be downloaded in chunks of this many bytes.

Decorators:
  • @util.positional(3)
Overrides: object.__init__

next_chunk(self, num_retries=0)

source code 
Get the next chunk of the download.

Args:
  num_retries: Integer, number of times to retry with randomized
        exponential backoff. If all retries fail, the raised HttpError
        represents the last request. If zero (default), we attempt the
        request only once.

Returns:
  (status, done): (MediaDownloadProgress, boolean)
     The value of 'done' will be True when the media has been fully
     downloaded or the total size of the media is unknown.

Raises:
  googleapiclient.errors.HttpError if the response was not a 2xx.
  httplib2.HttpLib2Error if a transport error has occurred.

Decorators:
  • @util.positional(1)