<SYSTEM_TASK:>
Solve the following problem using Python, implementing the functions described below, one line at a time
<END_TASK>
<USER_TASK:>
Description:
 def getResource(self, pid, destination=None, unzip=False, wait_for_bag_creation=True):
 """ Get a resource in BagIt format :param pid: The HydroShare ID of the resource :param destination: String representing the directory to save bag to. Bag will be saved to file named $(PID).zip in destination; existing file of the same name will be overwritten. If None, a stream to the zipped bag will be returned instead. :param unzip: True if the bag should be unzipped when saved to destination. Bag contents to be saved to directory named $(PID) residing in destination. Only applies when destination is not None. :param wait_for_bag_creation: True if to wait to download the bag in case the bag is not ready (bag needs to be recreated before it can be downloaded). :raises: HydroShareArgumentException if any arguments are invalid. :raises: HydroShareNotAuthorized if the user is not authorized to access the resource. :raises: HydroShareNotFound if the resource was not found. :raises: HydroShareHTTPException to signal an HTTP error :raise: HydroShareBagNotReady if the bag is not ready to be downloaded and wait_for_bag_creation is False :return: None if the bag was saved directly to disk. Or a generator representing a buffered stream of the bytes comprising the bag returned by the REST end point. """

        stream = self._getBagStream(pid, wait_for_bag_creation)
        if destination:
            self._storeBagOnFilesystem(stream, pid, destination, unzip)
            return None
        else:
            return stream