code: def getResourceFile(self, pid, filename, destination=None):
          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