• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

azjezz / psl / 22519606807

28 Feb 2026 11:11AM UTC coverage: 97.532% (-1.2%) from 98.733%
22519606807

push

github

web-flow
feat(network): rewrite networking stack with TLS, UDP, SOCKS5, CIDR, and IO utilities (#585)

860 of 937 new or added lines in 31 files covered. (91.78%)

15 existing lines in 6 files now uncovered.

7470 of 7659 relevant lines covered (97.53%)

42.83 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

92.86
/src/Psl/IO/copy.php
1
<?php
2

3
declare(strict_types=1);
4

5
namespace Psl\IO;
6

7
use Psl\Async;
8
use Psl\DateTime\Duration;
9

10
/**
11
 * Copy data from a read handle to a write handle until EOF.
12
 *
13
 * Reads from $reader until EOF and writes all data to $writer.
14
 *
15
 * @return int<0, max> The total number of bytes copied.
16
 *
17
 * @throws Exception\RuntimeException If a read or write error occurs.
18
 * @throws Exception\TimeoutException If the operation times out.
19
 */
20
function copy(ReadHandleInterface $reader, WriteHandleInterface $writer, null|Duration $timeout = null): int
21
{
22
    $timer = new Async\OptionalIncrementalTimeout($timeout, static function (): never {
6✔
NEW
23
        throw new Exception\TimeoutException('Copy operation timed out.');
×
24
    });
6✔
25

26
    $bytes_copied = 0;
6✔
27
    $buffer_size = 8192;
6✔
28

29
    while (true) {
6✔
30
        $data = $reader->read($buffer_size, $timer->getRemaining());
6✔
31
        if ($data === '') {
6✔
32
            if ($reader->reachedEndOfDataSource()) {
5✔
33
                break;
5✔
34
            }
35

36
            continue;
1✔
37
        }
38

39
        $writer->writeAll($data, $timer->getRemaining());
5✔
40
        $bytes_copied += \strlen($data);
5✔
41
    }
42

43
    /** @var int<0, max> */
44
    return $bytes_copied;
5✔
45
}
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2026 Coveralls, Inc