Skip to content

Commit fa9e266

Browse files
committed
Optimized downloadFile
1 parent 0fd4784 commit fa9e266

1 file changed

Lines changed: 8 additions & 3 deletions

File tree

src/Telegram/Bot.php

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -109,11 +109,16 @@ protected function replyAsPayload(string $method, array|object $arguments = []):
109109
*/
110110
public function downloadFile(string $path, string $destination, $timeout = 10) {
111111
try {
112-
$client = new GuzzleClient(['timeout' => $timeout]);
113-
$response = $client->request('GET', $this->apiURL . 'file/bot' . $this->token . "/$path");
112+
$client = new GuzzleClient([
113+
'timeout' => $timeout,
114+
'stream' => true,
115+
'sink' => $destination,
116+
]);
117+
$client->request('GET', $this->apiURL . 'file/bot' . $this->token . "/$path");
114118

115-
return (bool)@file_put_contents($destination, $response->getBody());
119+
return true;
116120
} catch(RequestException $e) {
121+
unlink($destination);
117122
return false;
118123
}
119124
}

0 commit comments

Comments
 (0)