libcloud.utils.files module

libcloud.utils.files.exhaust_iterator(iterator)[source]

Exhaust an iterator and return all data returned by it.

Parameters:

iterator (object which implements iterator interface.) – An object which implements an iterator interface or a File like object with read method.

:rtype str :return Data returned by the iterator.

libcloud.utils.files.guess_file_mime_type(file_path)[source]
libcloud.utils.files.read_in_chunks(iterator, chunk_size=None, fill_size=False, yield_empty=False)[source]

Return a generator which yields data in chunks.

Parameters:
  • iterator (object which implements iterator interface.) – An object which implements an iterator interface or a File like object with read method.

  • chunk_size (int) – Optional chunk size (defaults to CHUNK_SIZE)

  • fill_size (bool) – If True, make sure chunks are exactly chunk_size in length (except for last chunk).

  • yield_empty (bool) – If true and iterator returned no data, only yield empty bytes object

TODO: At some point in the future we could use byte arrays here if version >= Python 3. This should speed things up a bit and reduce memory usage.