docs: def _download_to_local(boto_conn, s3_path, fp, num_result_dir, delim=None):
      '''
      Downloads the contents of all objects in s3_path into fp
  
      Args:
          `boto_conn`: S3 connection object
  
          `s3_path`: S3 path to be downloaded
  
          `fp`: The file object where data is to be downloaded
      '''
      #Progress bar to display download progress
      def _callback(downloaded, total):
          '''
          Call function for upload.
  
          `downloaded`: File size already downloaded (int)
  
          `total`: Total file size to be downloaded (int)
          '''
          if (total is 0) or (downloaded == total):
              return
          progress = downloaded*100/total
          sys.stderr.write('\r[{0}] {1}%'.format('#'*progress, progress))
          sys.stderr.flush()
          
      m = _URI_RE.match(s3_path)
      bucket_name = m.group(1)
      bucket = boto_conn.get_bucket(bucket_name)
      retries = 6
      if s3_path.endswith('/') is False:
          #It is a file
          key_name = m.group(2)
          key_instance = bucket.get_key(key_name)
          while key_instance is None and retries > 0:
              retries = retries - 1
              log.info("Results file is not available on s3. Retry: " + str(6-retries))
              time.sleep(10)
              key_instance = bucket.get_key(key_name)
          if key_instance is None:
              raise Exception("Results file not available on s3 yet. This can be because of s3 eventual consistency issues.")
          log.info("Downloading file from %s" % s3_path)
          if delim is None:
              try:
                  key_instance.get_contents_to_file(fp)  # cb=_callback
              except boto.exception.S3ResponseError as e:
                  if (e.status == 403):
                      # SDK-191, boto gives an error while fetching the objects using versions which happens by default
                      # in the get_contents_to_file() api. So attempt one without specifying version.
                      log.warn("Access denied while fetching the s3 object. Retrying without specifying the version....")
                      key_instance.open()
                      fp.write(key_instance.read())
                      key_instance.close()
                  else:
                      raise
          else:
              # Get contents as string. Replace parameters and write to file.
              _read_iteratively(key_instance, fp, delim=delim)
  
      else:
          #It is a folder
          key_prefix = m.group(2)
          bucket_paths = bucket.list(key_prefix)
          for one_path in bucket_paths:
              name = one_path.name
  
              # Eliminate _tmp_ files which ends with $folder$
              if name.endswith('$folder$'):
                  continue
  
              log.info("Downloading file from %s" % name)
              if delim is None:
                  one_path.get_contents_to_file(fp)  # cb=_callback
              else:
                  _read_iteratively(one_path, fp, delim=delim)