def file_generator_limited(fileobj, count, chunk_size=65536):
 remaining = count
 while (remaining > 0):
  chunk = fileobj.read(min(chunk_size, remaining))
  chunklen = len(chunk)
  if (chunklen == 0):
   return
  remaining -= chunklen
  (yield chunk)

def file_generator_limited ( fileobj , count , chunk_size = 65536 ) : remaining = count while ( remaining > 0 ) : chunk = fileobj . read ( min ( chunk_size , remaining ) ) chunklen = len ( chunk ) if ( chunklen == 0 ) : return remaining -= chunklen ( yield chunk )
yield the given file object in chunks .