/** * {@inheritdoc} */ public function sendBinary(ReadableStream $stream, int $priority = 0) : Awaitable { return $this->writer->execute(function () use($stream) { $type = Frame::BINARY; $reserved = Frame::RESERVED1; $context = $this->deflate->getCompressionContext(); $len = 0; try { $chunk = (yield $stream->readBuffer(4092)); while (null !== ($next = (yield $stream->readBuffer(4092)))) { $chunk = \deflate_add($context, $chunk, \ZLIB_SYNC_FLUSH); $len += (yield $this->writeFrame(new Frame($type, $chunk, false, $reserved))); $chunk = $next; $type = Frame::CONTINUATION; $reserved = 0; } if ($chunk !== null) { $chunk = \substr(\deflate_add($context, $chunk, $this->deflate->getCompressionFlushMode()), 0, -4); $len += (yield $this->writeFrame(new Frame($type, $chunk, true, $reserved))); } return $len; } finally { $stream->close(); } }, $priority); }