docs: def save_as(self, target_dir=None):
          """
          Save the kecpkg service script to an (optional) target dir.
  
          Retains the filename of the service as known in KE-chain.
  
          .. versionadded:: 1.13
  
          :param target_dir: (optional) target dir. If not provided will save to current working directory.
          :type target_dir: basestring or None
          :raises APIError: if unable to download the service.
          :raises OSError: if unable to save the service kecpkg file to disk.
          """
          full_path = os.path.join(target_dir or os.getcwd(), self.filename)
  
          url = self._client._build_url('service_download', service_id=self.id)
          response = self._client._request('GET', url)
          if response.status_code != requests.codes.ok:  # pragma: no cover
              raise APIError("Could not download service script file ({})".format(response))
  
          with open(full_path, 'w+b') as f:
              for chunk in response:
                  f.write(chunk)