code: def download(remote_url, local_path=None, cache=True, extract=False):
      _bucket = bucket
      if re.match(r"^https?://", remote_url):
          protocol = "http"
      elif re.match(r"^s3?://", remote_url):
          require(lore.dependencies.S3)
          import boto3
          from botocore.exceptions import ClientError
  
          protocol = "s3"
          url_parts = urlparse(remote_url)
          remote_url = url_parts.path[1:]
          _bucket = boto3.resource("s3").Bucket(url_parts.netloc)
      else:
          if s3 is None or bucket is None:
              raise NotImplementedError(
                  "Cannot download from s3 without config/aws.cfg"
              )
          protocol = "s3"
          remote_url = prefix_remote_root(remote_url)
      if cache:
          if local_path is None:
              if protocol == "http":
                  filename = lore.env.parse_url(remote_url).path.split(
                      "/"
                  )[-1]
              elif protocol == "s3":
                  filename = remote_url
              local_path = os.path.join(lore.env.DATA_DIR, filename)
  
          if os.path.exists(local_path):
              return local_path
      elif local_path:
          raise ValueError(
              "You can't pass lore.io.download(local_path=X), unless you also pass cache=True"
          )
      elif extract:
          raise ValueError(
              "You can't pass lore.io.download(extract=True), unless you also pass cache=True"
          )
  
      with timer("DOWNLOAD: %s" % remote_url):
          temp_file, temp_path = tempfile.mkstemp(dir=lore.env.WORK_DIR)
          os.close(temp_file)
          try:
              if protocol == "http":
                  lore.env.retrieve_url(remote_url, temp_path)
              else:
                  _bucket.download_file(remote_url, temp_path)
          except ClientError as e:
              logger.error("Error downloading file: %s" % e)
              raise
  
      if cache:
          dir = os.path.dirname(local_path)
          if not os.path.exists(dir):
              try:
                  os.makedirs(dir)
              except os.FileExistsError:
                  pass  # race to create
  
          shutil.copy(temp_path, local_path)
          os.remove(temp_path)
  
          if extract:
              with timer("EXTRACT: %s" % local_path, logging.WARNING):
                  if local_path[-7:] == ".tar.gz":
                      with tarfile.open(local_path, "r:gz") as tar:
                          tar.extractall(os.path.dirname(local_path))
                  elif local_path[-4:] == ".zip":
                      import zipfile
  
                      with zipfile.ZipFile(local_path, "r") as zip:
                          zip.extractall(os.path.dirname(local_path))
  
      else:
          local_path = temp_path
      return local_path
  
file_path: lore/lore/io/__init__.py
imports: import logging
  import os
  import pickle
  import re
  import shutil
  import tarfile
  import tempfile
  import lore
  from lore.env import require, configparser
  from lore.util import timer
  from lore.io.connection import Connection
  from lore.io.multi_connection_proxy import MultiConnectionProxy
label_desc: Use image node_id 1 for calling a global function with example usage: download(remote_url, local_path, cache, extract) and returns: local_path, local_path