  def GetObject(self,
                gcs_path: str,
                out_file: Optional[str] = None) -> str:
    """Gets the contents of an object in a Google Cloud Storage bucket.

    Args:
      gcs_path (str): Full path to the object (ie: gs://bucket/dir1/dir2/obj)
      out_file (str): Path to the local file that will be written.
        If not provided, will create a temporary file.

    Returns:
      str: The filename of the written object.

    Raises:
      ResourceCreationError: If the file couldn't be downloaded.
    """
    if not gcs_path.startswith('gs://'):
      gcs_path = 'gs://' + gcs_path
    gcs_objects = self.GcsApi().objects() # pylint: disable=no-member
    (bucket, filename) = SplitStoragePath(gcs_path)
    request = gcs_objects.get_media(bucket=bucket, object=filename)

    if not out_file:
      outputdir = tempfile.mkdtemp()
      logger.info('Created temporary directory {0:s}'.format(outputdir))
      out_file = os.path.join(outputdir, os.path.basename(filename))

    stat = shutil.disk_usage(os.path.dirname(outputdir))
    om = self.GetObjectMetadata(gcs_path)
    if 'size' not in om:
      logger.warning('Unable to retrieve object metadata before fetching')
    else:
      if int(om['size']) > stat.free:
        raise errors.ResourceCreationError(
            'Target drive does not have enough space ({0!s} free vs {1!s} needed)'  # pylint: disable=line-too-long
            .format(stat.free, om['size']),
            __name__)

    with open(out_file, 'wb') as outputfile:
      downloader = googleapiclient.http.MediaIoBaseDownload(outputfile, request)

      done = False
      while not done:
        status, done = downloader.next_chunk()
        if status.total_size > stat.free:
          raise errors.ResourceCreationError(
              'Target drive does not have enough space ({0!s} free vs {1!s} needed)'  # pylint: disable=line-too-long
              .format(stat.free, status.total_size),
              __name__)
        logger.info('Download {}%.'.format(int(status.progress() * 100)))
      logger.info('File successfully written to {0:s}'.format(out_file))

    return out_file
Gets the contents of an object in a Google Cloud Storage bucket.

Args:
gcs_path (str): Full path to the object (ie: gs://bucket/dir1/dir2/obj)
out_file (str): Path to the local file that will be written.
If not provided, will create a temporary file.

Returns:
str: The filename of the written object.

Raises:
ResourceCreationError: If the file couldn't be downloaded.
libcloudforensics/providers/gcp/internal/storage.py