| @@ 547-560 (lines=14) @@ | ||
| 544 | * @param string &$buf |
|
| 545 | * @return callable |
|
| 546 | */ |
|
| 547 | protected function readAllGenHandler($cb, $size, &$offset, &$pri, &$buf) { |
|
| 548 | return function ($file, $data) use ($cb, $size, &$offset, &$pri, &$buf) { |
|
| 549 | $buf .= $data; |
|
| 550 | $offset += strlen($data); |
|
| 551 | $len = min($file->chunkSize, $size - $offset); |
|
| 552 | if ($offset >= $size) { |
|
| 553 | if ($cb) { |
|
| 554 | $cb($file, $buf); |
|
| 555 | } |
|
| 556 | return; |
|
| 557 | } |
|
| 558 | eio_read($file->fd, $len, $offset, $pri, $this->readAllGenHandler($cb, $size, $offset, $pri, $buf), $this); |
|
| 559 | }; |
|
| 560 | } |
|
| 561 | ||
| 562 | /** |
|
| 563 | * Reads whole file |
|
| @@ 600-611 (lines=12) @@ | ||
| 597 | * @param integer $pri |
|
| 598 | * @return callable |
|
| 599 | */ |
|
| 600 | protected function readAllChunkedGenHandler($cb, $chunkcb, $size, &$offset, $pri) { |
|
| 601 | return function ($file, $data) use ($cb, $chunkcb, $size, &$offset, $pri) { |
|
| 602 | $chunkcb($file, $data); |
|
| 603 | $offset += strlen($data); |
|
| 604 | $len = min($file->chunkSize, $size - $offset); |
|
| 605 | if ($offset >= $size) { |
|
| 606 | $cb($file, true); |
|
| 607 | return; |
|
| 608 | } |
|
| 609 | eio_read($file->fd, $len, $offset, $pri, $this->readAllChunkedGenHandler($cb, $chunkcb, $size, $offset, $pri), $file); |
|
| 610 | }; |
|
| 611 | } |
|
| 612 | ||
| 613 | /** |
|
| 614 | * Reads file chunk-by-chunk |
|