generated from Nodarx/template
feat: implement download
Signed-off-by: Sebastian Krupinski <krupinski01@gmail.com>
This commit is contained in:
@@ -20,5 +20,13 @@ interface ConnectionInterface
|
||||
|
||||
public function readBytes(int $length): string;
|
||||
|
||||
/**
|
||||
* Yield the literal payload in chunks without buffering the full content.
|
||||
* Reads exactly $length bytes from the socket, never crossing the literal boundary.
|
||||
*
|
||||
* @return \Generator<string>
|
||||
*/
|
||||
public function readBytesChunked(int $length, int $chunkSize = 8192): \Generator;
|
||||
|
||||
public function upgradeToTls(): void;
|
||||
}
|
||||
@@ -135,6 +135,26 @@ final class SocketConnection implements ConnectionInterface
|
||||
return $buffer;
|
||||
}
|
||||
|
||||
public function readBytesChunked(int $length, int $chunkSize = 8192): \Generator
|
||||
{
|
||||
if ($length < 0) {
|
||||
throw new ImapException('IMAP socket cannot read a negative number of bytes.');
|
||||
}
|
||||
|
||||
$remaining = $length;
|
||||
|
||||
while ($remaining > 0) {
|
||||
$chunk = fread($this->stream(), min($chunkSize, $remaining));
|
||||
|
||||
if ($chunk === false || $chunk === '') {
|
||||
throw new ImapException('Failed to read literal payload from IMAP socket.');
|
||||
}
|
||||
|
||||
$remaining -= strlen($chunk);
|
||||
yield $chunk;
|
||||
}
|
||||
}
|
||||
|
||||
public function upgradeToTls(): void
|
||||
{
|
||||
$stream = $this->stream();
|
||||
|
||||
Reference in New Issue
Block a user