Пример #1
0
 /**
  * Returns a readable plain text stream for the given ResponseInterface
  *
  * @param PromiseInterface $promise Promise<ResponseInterface>
  * @return ReadableStreamInterface
  */
 public function parsePlainStream(PromiseInterface $promise)
 {
     // text/plain
     return Stream\unwrapReadable($promise->then(function (ResponseInterface $response) {
         return $response->getBody();
     }));
 }
Пример #2
0
 /**
  * Reads the file contents of the given file path as a readable stream
  *
  * This works for files of arbitrary sizes as only small chunks have to
  * be kept in memory. The resulting stream is a well-behaving readable stream
  * that will emit the normal stream events.
  *
  * @param string      $path
  * @param string|null $revision
  * @return ReadableStreamInterface
  * @throws InvalidArgumentException
  * @see self::fetchFile()
  */
 public function fetchFileStream($path, $revision = null)
 {
     if (substr($path, -1) === '/') {
         throw new InvalidArgumentException('File path MUST NOT end with trailing slash');
     }
     // TODO: fetching a directory redirects to path with trailing slash
     // TODO: status returns 200 OK, but displays an error message anyways..
     // TODO: see not-a-file.html
     // TODO: reject all paths with trailing slashes
     return Stream\unwrapReadable($this->browser->withOptions(array('streaming' => true))->get($this->uri->expand('{+path}?view=co{&pathrev}', array('path' => $path, 'pathrev' => $revision)))->then(function (ResponseInterface $response) {
         // the body implements ReadableStreamInterface, so let's just return this to the unwrapper
         return $response->getBody();
     }));
 }
 public function testClosingStreamWillCloseStreamFromCancellationHandler()
 {
     $input = new ReadableStream();
     $promise = new \React\Promise\Promise(function () {
     }, function ($resolve) use($input) {
         $resolve($input);
     });
     $stream = Stream\unwrapReadable($promise);
     $stream->on('close', $this->expectCallableOnce());
     $stream->close();
     $this->assertFalse($input->isReadable());
 }
 public function testClosingStreamWillCloseStreamIfItIgnoredCancellationAndResolvesLater()
 {
     $this->markTestIncomplete();
     $input = new ReadableStream();
     $loop = $this->loop;
     $promise = new Promise\Promise(function ($resolve) use($loop, $input) {
         $loop->addTimer(0.001, function () use($resolve, $input) {
             $resolve($input);
         });
     });
     $stream = Stream\unwrapReadable($promise);
     $stream->on('close', $this->expectCallableOnce());
     $stream->close();
     Block\await($promise, $this->loop);
     $this->assertFalse($input->isReadable());
 }