2023-04-15 23:29:27 +08:00
|
|
|
<?php
|
|
|
|
|
|
|
|
|
|
namespace Kiri\Router;
|
|
|
|
|
|
2023-04-15 23:31:16 +08:00
|
|
|
class StreamResponse extends Response
|
2023-04-15 23:29:27 +08:00
|
|
|
{
|
|
|
|
|
|
|
|
|
|
public int $limit;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* @param object $response
|
|
|
|
|
* @return void
|
|
|
|
|
*/
|
|
|
|
|
public function write(object $response): void
|
|
|
|
|
{
|
|
|
|
|
$body = $this->getBody();
|
|
|
|
|
$total = ceil($this->limit / $body->getSize());
|
|
|
|
|
|
|
|
|
|
for ($i = 0; $i < $total; $i++) {
|
|
|
|
|
$body->seek($i);
|
|
|
|
|
|
|
|
|
|
$response->write($body->read($this->limit));
|
|
|
|
|
}
|
|
|
|
|
$response->end();
|
|
|
|
|
}
|
|
|
|
|
}
|