<SYSTEM_TASK:>
Solve the following problem using Python, implementing the functions described below, one line at a time
<END_TASK>
<USER_TASK:>
Description:
 def getResourceFile(self, pid, filename, destination=None):
 """ Get a file within a resource. :param pid: The HydroShare ID of the resource :param filename: String representing the name of the resource file to get. :param destination: String representing the directory to save the resource file to. If None, a stream to the resource file will be returned instead. :return: The path of the downloaded file (if destination was specified), or a stream to the resource file. :raises: HydroShareArgumentException if any parameters are invalid. :raises: HydroShareNotAuthorized if user is not authorized to perform action. :raises: HydroShareNotFound if the resource was not found. :raises: HydroShareHTTPException if an unexpected HTTP response code is encountered. """

        url = "{url_base}/resource/{pid}/files/{filename}".format(url_base=self.url_base,
                                                                  pid=pid,
                                                                  filename=filename)

        if destination:
            if not os.path.isdir(destination):
                raise HydroShareArgumentException("{0} is not a directory.".format(destination))
            if not os.access(destination, os.W_OK):
                raise HydroShareArgumentException("You do not have write permissions to directory '{0}'.".format(destination))

        r = self._request('GET', url, stream=True)
        if r.status_code != 200:
            if r.status_code == 403:
                raise HydroShareNotAuthorized(('GET', url))
            elif r.status_code == 404:
                raise HydroShareNotFound((pid, filename))
            else:
                raise HydroShareHTTPException((url, 'GET', r.status_code))

        if destination is None:
            return r.iter_content(STREAM_CHUNK_SIZE)
        else:
            filepath = os.path.join(destination, filename)
            with open(filepath, 'wb') as fd:
                for chunk in r.iter_content(STREAM_CHUNK_SIZE):
                    fd.write(chunk)
            return filepath