<commit_before><?php
  namespace xp\install;

  use \webservices\rest\RestClient;
  use \webservices\rest\RestRequest;
  use \util\cmd\Console;
  use \io\Folder;
  use \io\File;

  class XarRelease extends \lang\Object implements Origin {
    private $client;
    private $release;

    /**
     * Creates a new instance
     *
     * @param string $vendor
     * @param string $module
     * @param string $branch
     */
    public function __construct($vendor, $module, $branch) {
      $this->client= new RestClient('http://builds.planet-xp.net/');
      $this->release= new RestRequest(sprintf(
        '%s/%s/%s',
        $vendor,
        $module,
        $branch
      ));
    }

    /**
     * Fetches this origin into a given target folder
     *
     * @param  io.Folder $target
     */
    public function fetchInto(Folder $target) {
      $r= $this->client->execute($this->release);
      if (200 !== $r->status()) {
        throw new \lang\IllegalArgumentException($r->message().': '.$this->resource->toString());
      }
      $release= $r->data();

      // Download files
      $pth= create(new File($target, 'class.pth'))->getOutputStream();
      foreach ($release['files'] as $file) {
        $d= $this->client->execute(new RestRequest($this->release->getResource().'/'.$file['name']));
        Console::writeLine('>> ', $file['name']);

        $f= new File($target, $file['name']);
        with ($out= $f->getOutputStream()); {
          $out->write($d->content());
          $out->close();
        }
        $pth->write($file['name']."\n");
      }
      $pth->close();
    }
  }
?><commit_msg>- Make use of new RestResponse::stream() method<commit_after><?php
  namespace xp\install;

  use \webservices\rest\RestClient;
  use \webservices\rest\RestRequest;
  use \util\cmd\Console;
  use \io\streams\StreamTransfer;
  use \io\Folder;
  use \io\File;

  class XarRelease extends \lang\Object implements Origin {
    private $client;
    private $release;

    /**
     * Creates a new instance
     *
     * @param string $vendor
     * @param string $module
     * @param string $branch
     */
    public function __construct($vendor, $module, $branch) {
      $this->client= new RestClient('http://builds.planet-xp.net/');
      $this->release= new RestRequest(sprintf(
        '%s/%s/%s',
        $vendor,
        $module,
        $branch
      ));
    }

    /**
     * Fetches this origin into a given target folder
     *
     * @param  io.Folder $target
     */
    public function fetchInto(Folder $target) {
      $r= $this->client->execute($this->release);
      if (200 !== $r->status()) {
        throw new \lang\IllegalArgumentException($r->message().': '.$this->resource->toString());
      }
      $release= $r->data();
      Console::writeLine('Release ', $release['version']['number'], ' published ', $release['published']);

      // Download files
      $pth= create(new File($target, 'class.pth'))->getOutputStream();
      foreach ($release['files'] as $file) {
        $d= $this->client->execute(new RestRequest($this->release->getResource().'/'.$file['name']));
        Console::writeLine('>> ', $file['name']);

        $tran= new StreamTransfer($d->stream(), create(new File($target, $file['name']))->getOutputStream());
        $tran->transferAll();
        $tran->close();

        $pth->write($file['name']."\n");
      }
      $pth->close();
    }
  }
?>
{'fraction_non_alphanumeric': 0.18726152039917815, 'fraction_numerical': 0.0017610801291458762, 'mean_word_length': 2.542619542619543, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 51, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 2, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '2552586', 'n_tokens_mistral': 1054, 'n_tokens_neox': 1039, 'n_words': 217}